26 #include <Classes.hpp>
27 #include <Controls.hpp>
28 #include <StdCtrls.hpp>
30 #include <Buttons.hpp>
31 #include <ExtCtrls.hpp>
33 #include <Dialogs.hpp>
34 #include <Graphics.hpp>
35 #include <ComCtrls.hpp>
52 #pragma package(smart_init)
62 TTrain::TTrain(
int Caller,
int RearStartElementIn,
int RearStartExitPosIn, AnsiString InputCode,
int StartSpeedIn,
int MassIn,
double MaxRunningSpeedIn,
63 double MaxBrakeRateIn,
double PowerAtRailIn,
TTrainMode TrainModeIn,
TTrainDataEntry *TrainDataEntryPtrIn,
int RepeatNumberIn,
int IncrementalMinutesIn,
64 int IncrementalDigitsIn,
int SignallerMaxSpeedIn): RearStartElement(RearStartElementIn), RearStartExitPos(RearStartExitPosIn), HeadCode(InputCode),
65 StartSpeed(StartSpeedIn), Mass(MassIn), MaxRunningSpeed(MaxRunningSpeedIn), MaxBrakeRate(MaxBrakeRateIn), PowerAtRail(PowerAtRailIn),
66 TrainMode(TrainModeIn), TrainDataEntryPtr(TrainDataEntryPtrIn), RepeatNumber(RepeatNumberIn), IncrementalMinutes(IncrementalMinutesIn),
67 IncrementalDigits(IncrementalDigitsIn), SignallerMaxSpeed(SignallerMaxSpeedIn)
78 AnsiString(RearStartExitPosIn) +
"," + AnsiString(InputCode) +
"," + AnsiString(StartSpeedIn) +
"," + AnsiString(MassIn) +
"," +
79 AnsiString(TrainModeIn));
123 for(
int x = 0; x < 4; x++)
132 for(
int x = 0; x < 4; x++)
141 for(
int x = 0; x < 4; x++)
146 for(
int x = 0; x < 4; x++)
150 for(
int x = 0; x < 3; x++)
187 for(
int x = 0; x < 4; x++)
232 throw Exception(
"Error in attempting to delete FrontCodePtr");
236 for(
int x = 0; x < 4; x++)
240 throw Exception(
"Error in attempting to delete BackgroundPtr[" + AnsiString(x) +
"]");
245 for(
int x = 0; x < 4; x++)
249 throw Exception(
"Error in attempting to delete HeadCodeGrPtr[" + AnsiString(x) +
"]");
278 int NextElementPosition, NextEntryPos, ElementLength, SpeedLimit;
340 bool TempDerail =
false;
384 else if((NextElementPosition > -1) && (NextEntryPos > -1))
450 throw Exception(
"Error, LeadElement Exit Connection is NotSet");
461 for(
int x = 0; x < 4; x++)
468 for(
int x = 0; x < 4; x++)
700 if((random(RandRange)) == 0)
715 int LockedVectorNumber;
928 if(BufferLocation ==
"")
931 if((BufferLocation ==
"") || (BufferLocation != ExpectedLocation))
995 int NextElementPosition, NextEntryPos;
1019 NextElementPosition = -1;
1023 if((NextElementPosition > -1) && (NextEntryPos > -1))
1138 AnsiString StationName;
1149 throw Exception(
"Error - Stopped at through station but neither lead nor mid elements have a name");
1163 if((NextElementPosition > -1) && (NextEntryPos > -1))
1290 if(NextElementPosition > -1)
1329 AnsiString Loc =
"";
1330 bool LocNamed =
false;
1359 Loc =
"outside railway";
1385 NextElementPosition = -1;
1398 if((NextElementPosition > -1) && (NextEntryPos > -1) && !
SPADFlag)
1417 if((NextElementPosition > -1) && (NextEntryPos > -1))
1456 FirstPair.second).
GetELink() == TempELink))
1461 SecondPair.second).
GetELink() == TempELink))
1476 FirstPair.second).
GetELink() == TempELink))
1481 SecondPair.second).
GetELink() == TempELink))
1496 FirstPair.second).
GetELink() == TempELink))
1501 SecondPair.second).
GetELink() == TempELink))
1534 ContinuationAutoSigEntry.
RouteNumber = RouteNumber;
1537 int NewLastElement = 0, NewLastExitPos = 0;
1551 if(NewLastElement == -1)
1554 throw Exception(
"Error, Connection = -1 in Continuation loop in UpdateTrain");
1557 if(NewLastExitPos == -1)
1559 throw Exception(
"Error, ConnLinkPos = -1 in Continuation loop in UpdateTrain");
1561 LastElement = NewLastElement;
1562 LastExitPos = NewLastExitPos;
1565 if(CumDistance < 1200)
1571 int FirstDistance = 0;
1572 if(CumDistance >= 1200)
1573 FirstDistance = 100;
1575 FirstDistance = 1200 - CumDistance;
1576 if(FirstDistance < 100)
1577 FirstDistance = 100;
1602 if(VectorIT->RouteNumber == RouteNumber)
1647 LockedVectorNumber)))
1808 for(
int x = 0; x < 4; x++)
1815 for(
int x = 0; x < 4; x++)
1842 if((LeadElementTrainID > -1) && (LeadElementTrainID !=
TrainID))
1847 if(OtherTrainEntryPos == -1)
1849 throw Exception(
"Error - OtherTrainEntryPos not set");
1868 int OtherTrainID = -1;
1869 if((MidExitLinkNum == 1) || (MidExitLinkNum == 3) || (MidExitLinkNum == 7) || (MidExitLinkNum == 9))
1964 bool StopRequired =
false;
1977 int NextElementEntryPos = -1;
1978 int NextElementExitPos = -1;
1979 bool TrainOnNextElement =
false;
1980 bool StopSignalAtNextElement =
false;
1981 if(ForwardConnection)
1989 StopSignalAtNextElement = ((NextTrackElement.
Config[NextElementExitPos] ==
Signal) && (NextTrackElement.
Attribute == 0));
1992 if(TrainAtStopLinkPos1 || TrainAtStopLinkPos2 || (ForwardConnection && (TrainOnNextElement || StopSignalAtNextElement)))
2048 throw Exception(
"Error, Straddle shouldn't be LeadMid prior to resetting at exit from UpdateTrain");
2262 if(Code.Length() != 4)
2264 for(
int x = 1; x < 5; x++)
2271 for(
int x = 0; x < 4; x++)
2419 throw Exception(
"Error in GetOffsetValues - Link value wrong");
2431 if((EntryLink == 1) || (EntryLink == 2) || (EntryLink == 4) || (EntryLink == 7))
2442 AnsiString(
VOffset) +
"," + AnsiString(Element) +
"," + AnsiString(EntryPos) +
"," +
HeadCode);
2451 TRect SourceRect, DestRect;
2453 DestRect.init(0, 0, 8, 8);
2456 Graphics::TBitmap *TempGraphic =
new Graphics::TBitmap;
2458 TempGraphic->PixelFormat = pf8bit;
2459 TempGraphic->Width = 16;
2460 TempGraphic->Height = 16;
2466 TempGraphic->Transparent =
true;
2470 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2471 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2475 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2481 else if(TempElement.
SpeedTag == 89)
2483 else if(TempElement.
SpeedTag == 90)
2485 else if(TempElement.
SpeedTag == 91)
2487 else if(TempElement.
SpeedTag == 92)
2489 else if(TempElement.
SpeedTag == 93)
2491 else if(TempElement.
SpeedTag == 94)
2493 else if(TempElement.
SpeedTag == 95)
2495 TempGraphic->Transparent =
true;
2499 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2500 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2502 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2509 for(
int x = 0; x < 40; x++)
2524 TempGraphic->Transparent =
true;
2528 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2529 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2531 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2545 TempGraphic->Transparent =
true;
2549 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2550 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2553 TempGraphic->Canvas->Draw(0, 0, TempElement.
GraphicPtr);
2555 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2560 TempGraphic->Transparent =
true;
2564 int BDVectorPos = -1;
2573 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2578 TempGraphic->Transparent =
true;
2582 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2583 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2585 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2591 TempGraphic->Transparent =
true;
2595 TempGraphic->Canvas->Draw(0, 0, EXGraphicPtr);
2596 TempGraphic->Canvas->Draw(0, 0, EntryDirectionGraphicPtr);
2598 GraphicPtr->Canvas->CopyRect(DestRect, TempGraphic->Canvas, SourceRect);
2864 throw Exception(
"Error, same train on two different bridge tracks");
2910 AnsiString(EntryPos) +
"," +
HeadCode);
2928 throw Exception(
"Error, TrackVectorPosition set but not EntryPos in SetTrainElementID");
2943 AnsiString(EntryPos) +
"," +
HeadCode);
2952 throw Exception(
"Error, TrackVectorPosition set but not EntryPos in ResetTrainElementID");
2979 AnsiString(ElementEntryPos) +
"," + AnsiString(
HOffset) +
"," + AnsiString(
VOffset) +
"," + AnsiString(StraddleValue) +
"," +
HeadCode);
2980 int LockedVectorNumber;
2992 TRect SourceRect, DestRect;
2993 DestRect.init(0, 0, 8, 8);
3000 int FirstELink, SecondELink = -1;
3003 if(RoutePair2.first > -1)
3010 if(SecondELink == -1)
3012 throw Exception(
"Error - Second ELink should be set but isn't in PlotAlternativeTrackRouteGraphic [1]");
3017 throw Exception(
"Error - First & Second ELinks have same value in PlotAlternativeTrackRouteGraphic");
3027 Graphics::TBitmap *DestGraphic =
new Graphics::TBitmap;
3028 DestGraphic->PixelFormat = pf8bit;
3029 DestGraphic->Width = 8;
3030 DestGraphic->Height = 8;
3031 DestGraphic->Transparent =
true;
3034 DestGraphic->Canvas->CopyRect(DestRect, RouteElement.
GetRouteEXGraphicPtr()->Canvas, SourceRect);
3043 PrefDirElement, LockedVectorNumber))
3058 if(ElementEntryPos > 1)
3080 AnsiString(EntryPos) +
"," +
HeadCode);
3082 bool WrongRoute =
false;
3107 int LinkNumber = TrackElement.
Link[EntryPos];
3108 if((LinkNumber == 1) || (LinkNumber == 3) || (LinkNumber == 7) || (LinkNumber == 9))
3113 bool LogActionErrorCalled =
false;
3122 LogActionErrorCalled =
true;
3138 else if(LinkNumber == 3)
3145 LogActionErrorCalled =
true;
3161 else if(LinkNumber == 7)
3168 LogActionErrorCalled =
true;
3184 else if(LinkNumber == 9)
3191 LogActionErrorCalled =
true;
3222 else if((RouteElement.
GetELinkPos() == 2) && (EntryPos == 0) && PointsAtElement)
3227 else if((RouteElement.
GetELinkPos() == 0) && (EntryPos == 2) && PointsAtElement)
3237 else if((RouteElement.
GetXLinkPos() == 2) && (EntryPos == 0) && PointsAtElement)
3242 else if((RouteElement.
GetXLinkPos() == 0) && (EntryPos == 2) && PointsAtElement)
3251 throw Exception(
"Error, Element in route but no route found in CheckAndCancelRouteForWrongEndEntry");
3269 bool ColourError =
false, ColourError2 =
false;
3273 ColourError2 =
true;
3274 for(
int x = 0; x < 4; x++)
3278 ColourError2 =
true;
3283 "ERROR: Colour depth insufficient to display train colours properly. Please ensure that the 'safe' (web) palette of 256 colours can be displayed");
3288 for(
int x = 0; x < 4; x++)
3375 AnsiString(EntryPos) +
"," +
HeadCode);
3376 int EntryHalfLength, CurrentElementHalfLength, NextElementHalfLength, CumulativeLength = 0, CurrentTrackVectorPosition = TrackVectorPosition;
3377 int DistanceAtHalfBraking, DistanceAtThreeQuarterBraking, ExitPos, NextTrackVectorPosition, NextEntryPos;
3378 bool RedSignalFlag =
false, BuffersFlag =
false, StationFlag =
false, BuffersOrContinuationNowFlag =
false, ContinuationNextFlag =
false,
3379 TrainInFrontInSignallerModeFlag =
false;
3380 double LimitingSpeed, FrontElementMaxSpeed, MaxExitSpeedAtHalfBrakingSquared, MaxExitSpeedAtHalfBraking, NextSpeedLimit, TempBrakeRate;
3381 double ExitSpeedHalfSquared, ExitSpeedFullSquared;
3382 bool SignallerStopRequired =
false;
3393 if(CurrentTrackVectorPosition > -1)
3397 if((EntryPos == 0) || (EntryPos == 2))
3410 else if(EntryPos == 1)
3434 EntryHalfLength = CurrentElementHalfLength;
3439 throw Exception(
"Error - CurrentTrackVectorPosition < 0 in SetTrainMovementValues");
3443 throw Exception(
"Error - HalfLength or SpeedLimit < 0 in SetTrainMovementValues");
3489 FrontElementMaxSpeed = LimitingSpeed;
3520 double ExitSpeedAtMaxBraking;
3525 ExitSpeedAtMaxBraking = 0;
3535 if(ExitSpeedAtMaxBraking > LimitingSpeed)
3537 SpeedToUse = ExitSpeedAtMaxBraking;
3541 SpeedToUse = LimitingSpeed;
3556 RedSignalFlag =
false;
3557 BuffersFlag =
false;
3558 StationFlag =
false;
3559 BuffersOrContinuationNowFlag =
false;
3560 ContinuationNextFlag =
false;
3563 CumulativeLength += (2 * CurrentElementHalfLength);
3566 SignallerStopRequired =
true;
3588 bool StopRequired =
false;
3600 StationFlag =
false;
3607 BuffersOrContinuationNowFlag =
true;
3609 if(!BuffersOrContinuationNowFlag && !BuffersFlag && !StationFlag)
3613 if((EntryPos == 0) || (EntryPos == 2))
3627 if(NextTrackVectorPosition > -1)
3632 if((NextEntryPos == 0) || (NextEntryPos == 2))
3645 else if(NextEntryPos == 1)
3658 if(NextEntryPos > 1)
3672 throw Exception(
"Error - Trying to access NextTrackVectorPosition when none present in SetTrainMovementValues");
3683 RedSignalFlag =
true;
3702 TrainInFrontInSignallerModeFlag =
true;
3726 if(RedSignalFlag || BuffersFlag || StationFlag || TrainInFrontInSignallerModeFlag || SignallerStopRequired ||
StepForwardFlag)
3738 double MaxHalfSpeed;
3742 if(MaxHalfSpeedAtHalfBraking > FrontElementMaxSpeed)
3743 MaxHalfSpeed = FrontElementMaxSpeed;
3745 MaxHalfSpeed = MaxHalfSpeedAtHalfBraking;
3752 bool HalfSpeedLimited =
false;
3756 HalfSpeedLimited =
true;
3781 if(HalfSpeedLimited)
3802 if(SignallerStopRequired)
3818 int TempMaxExitSpeed;
3821 if(MaxExitSpeedAtHalfBrakingSquared < 10)
3822 MaxExitSpeedAtHalfBraking = 0;
3824 MaxExitSpeedAtHalfBraking = sqrt(MaxExitSpeedAtHalfBrakingSquared);
3827 if(MaxExitSpeedAtHalfBraking > FrontElementMaxSpeed)
3828 TempMaxExitSpeed = FrontElementMaxSpeed;
3830 TempMaxExitSpeed = MaxExitSpeedAtHalfBraking;
3840 if(ExitSpeedHalfSquared < 10)
3846 if(ExitSpeedFullSquared < 10)
3910 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
3911 ExitTimeFull =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
3931 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
3932 ExitTimeHalf =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
3942 if(!BuffersOrContinuationNowFlag)
3944 if(NextSpeedLimit < LimitingSpeed)
3945 LimitingSpeed = NextSpeedLimit;
3948 int TempMaxExitSpeed;
3952 if(MaxExitSpeedAtHalfBrakingSquared < 10)
3953 MaxExitSpeedAtHalfBraking = 0;
3955 MaxExitSpeedAtHalfBraking = sqrt(MaxExitSpeedAtHalfBrakingSquared);
3956 if(MaxExitSpeedAtHalfBraking > FrontElementMaxSpeed)
3957 TempMaxExitSpeed = FrontElementMaxSpeed;
3959 TempMaxExitSpeed = MaxExitSpeedAtHalfBraking;
3967 TempBrakeRate = ((
EntrySpeed *
EntrySpeed) - (LimitingSpeed * LimitingSpeed)) / 3.6 / 3.6 / 2 / CumulativeLength;
3976 if(!BuffersOrContinuationNowFlag)
3978 CurrentTrackVectorPosition = NextTrackVectorPosition;
3979 EntryPos = NextEntryPos;
3980 CurrentElementHalfLength = NextElementHalfLength;
3983 ContinuationNextFlag =
true;
3987 while(((CumulativeLength -
FrontElementLength) < DistanceAtHalfBraking) && ((!BuffersOrContinuationNowFlag && !ContinuationNextFlag) ||
4007 if(ExitSpeedHalfSquared < 10)
4013 if(ExitSpeedFullSquared < 10)
4067 double DeltaExitTimeToMaxInSecs;
4068 double DistanceToMax;
4077 DeltaExitTimeToMaxInSecs = 2 * EntryHalfLength * 3.6 /
EntrySpeed;
4079 DistanceToMax = EntryHalfLength;
4082 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4083 ExitTimeFull =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4096 double DeltaExitTimeToMaxInSecs;
4097 double DistanceToMax;
4106 DeltaExitTimeToMaxInSecs = 2 * EntryHalfLength * 3.6 /
EntrySpeed;
4108 DistanceToMax = EntryHalfLength / 2;
4111 double DeltaRemainingTimeInSecs = 3.6 * RemainingDistance /
MaxExitSpeed;
4112 ExitTimeHalf =
EntryTime + TDateTime((DeltaExitTimeToMaxInSecs + DeltaRemainingTimeInSecs) / 86400.0);
4123 if(ExitSpeedHalfSquared < 10)
4129 if(ExitSpeedFullSquared < 10)
4144 if((EntryPos == 0) || (EntryPos == 2))
4158 if(NextTrackVectorPosition > -1)
4160 int NextElementLength;
4161 if(NextEntryPos > 1)
4169 double NextStoppingSpeed = sqrt(3.6 * 3.6 * 2 *
BrakeRate * NextElementLength);
4305 if((Ptr->Command ==
"cdt") || (Ptr->FormatType ==
Repeat))
4309 if((Ptr->ArrivalTime > TDateTime(-1)) && (Ptr->LocationName == Name))
4318 if((Ptr->EventTime > TDateTime(-1)) && (Ptr->LocationName == Name) && (Ptr->Command ==
"pas"))
4343 int CurrentTrackVectorPosition =
LeadElement, NextTrackVectorPosition;
4361 CurrentTrackVectorPosition).
Attribute != 4))
4397 if((EntryPos == 0) || (EntryPos == 2))
4411 CurrentTrackVectorPosition = NextTrackVectorPosition;
4412 EntryPos = NextEntryPos;
4436 throw Exception(
"Error - failed to set ReturnVal in ClearToNextSignal()");
4460 bool PlatformFoundFlag =
false, StopRequired =
false, SkipRouteCheck =
false, RouteOrPartRouteSet =
false;
4461 int CurrentTrackVectorPosition =
LeadElement, NextTrackVectorPosition, ElementNumber = 0, Distance = 0;
4462 int RouteStartPosition;
4464 int PlatformPosition;
4466 int EntryPos =
LeadEntryPos, ExitPos, NextEntryPos, RouteID;
4505 if(OtherTrain.
LeadElement == CurrentTrackVectorPosition)
4508 if((OtherCommand ==
"Fjo") || (OtherCommand ==
"jbo") || (OtherCommand ==
"cdt") || (OtherCommand ==
"Frh") ||
4554 if(!PlatformFoundFlag)
4555 PlatformPosition = CurrentTrackVectorPosition;
4557 PlatformFoundFlag =
true;
4573 if((EntryPos == 0) || (EntryPos == 2))
4608 if(ElementNumber < 2)
4609 SkipRouteCheck =
true;
4611 SkipRouteCheck =
false;
4612 if(ElementNumber == 1)
4614 RouteStartPosition = CurrentTrackVectorPosition;
4624 if(ElementNumber > 1)
4627 RouteOrPartRouteSet =
true;
4629 RouteOrPartRouteSet =
false;
4631 if(!SkipRouteCheck && !RouteOrPartRouteSet)
4638 int ExitLink = CurrentTrackElement.
Link[ExitPos];
4639 if((ExitLink == 1) || (ExitLink == 3) || (ExitLink == 7) || (ExitLink == 9))
4651 Distance += CurrentTrackElement.
Length01;
4653 Distance += CurrentTrackElement.
Length23;
4654 NextTrackVectorPosition = CurrentTrackElement.
Conn[ExitPos];
4655 NextEntryPos = CurrentTrackElement.
ConnLinkPos[ExitPos];
4656 CurrentTrackVectorPosition = NextTrackVectorPosition;
4657 EntryPos = NextEntryPos;
4694 return RepeatHeadCode;
4715 bool FrontValid =
false, RearValid =
false;
4716 TTrackElement FrontAdjacentTrackElement, RearAdjacentTrackElement;
4720 TrainToBeJoinedBy = NULL;
4734 int TrainToBeJoinedByID = -1;
4755 if((TrainToBeJoinedByID < 0) && RearValid)
4774 if(TrainToBeJoinedByID < 0)
4776 TrainToBeJoinedBy = NULL;
4781 if(!TrainToBeJoinedBy->
Stopped())
4783 TrainToBeJoinedBy = NULL;
4794 TDateTime TimetableNonRepeatTime,
bool Warning)
4829 AnsiString(ActionType) +
"," + LocationName +
"," +
HeadCode);
4830 AnsiString BaseLog =
"", WarningBaseLog =
"", PerfLog =
"", ActionLog =
"";
4831 int IntMinsLate = 0;
4835 ActionLog =
" arrived at ";
4843 ActionLog =
" terminated at ";
4847 ActionLog =
" departed from ";
4848 if(ActionType ==
Pass)
4849 ActionLog =
" passed ";
4851 ActionLog =
" created at ";
4852 if(ActionType ==
Enter)
4853 ActionLog =
" entered railway at ";
4854 if(ActionType ==
Leave)
4855 ActionLog =
" left railway at ";
4857 ActionLog =
" split from front to ";
4859 ActionLog =
" split from rear to ";
4861 ActionLog =
" joined by ";
4863 ActionLog =
" changed direction at ";
4865 ActionLog =
" became new service ";
4867 ActionLog =
" taken under signaller control at ";
4869 ActionLog =
" restored to timetable control at ";
4873 ActionLog =
" REMOVED FROM RAILWAY DUE TO CRASH at ";
4875 ActionLog =
" REMOVED FROM RAILWAY DUE TO DERAILMENT at ";
4877 ActionLog =
" REMOVED FROM RAILWAY at ";
4880 ActionLog =
" received signaller authority to proceed";
4882 ActionLog =
" received signaller authority to step forward";
4884 ActionLog =
" changed direction under signaller control at ";
4886 ActionLog =
" received signaller authority to pass red signal";
4888 ActionLog =
" received signaller instruction to stop";
4890 ActionLog =
" stopped on signaller instruction ";
4892 ActionLog =
" joined under signaller control by ";
4894 ActionLog =
" suffered an onboard power failure at ";
4896 ActionLog =
" failure repaired at ";
4898 ActionLog =
" left railway under signaller control at ";
4899 if(OtherHeadCode !=
"")
4900 OtherHeadCode +=
" at ";
4906 WarningBaseLog =
HeadCode + ActionLog + OtherHeadCode + LocationName;
4912 bool TimePerformance =
true;
4920 TimePerformance =
false;
4924 double MinsLate = ((double)(ActualTime -
GetTrainTime(1, TimetableNonRepeatTime))) * 1440;
4934 IntMinsLate = int(ceil(MinsLate));
4938 IntMinsLate = int(floor(MinsLate));
4940 if(IntMinsLate == 0)
4942 PerfLog =
" on time";
4944 else if(IntMinsLate == 1)
4945 PerfLog =
" 1 minute late";
4946 else if(IntMinsLate == -1)
4947 PerfLog =
" 1 minute early";
4948 else if(IntMinsLate > 1)
4949 PerfLog =
" " + AnsiString(IntMinsLate) +
" minutes late";
4950 else if(IntMinsLate < -1)
4952 int PosIntMinsLate = -IntMinsLate;
4953 PerfLog =
" " + AnsiString(PosIntMinsLate) +
" minutes early";
4955 if(LocationName.Pos(
'-') > 0)
4957 PerfLog =
"," + PerfLog;
4970 if((ActionType ==
Arrive) && (IntMinsLate == 0))
4974 else if((ActionType ==
Arrive) && (IntMinsLate > 0))
4979 else if((ActionType ==
Arrive) && (IntMinsLate < 0))
4984 else if((ActionType ==
Pass) && (IntMinsLate == 0))
4988 else if((ActionType ==
Pass) && (IntMinsLate > 0))
4993 else if((ActionType ==
Pass) && (IntMinsLate < 0))
4998 else if((ActionType ==
Depart) && (IntMinsLate == 0))
5002 else if((ActionType ==
Depart) && (IntMinsLate > 0))
5021 AnsiString LocName =
"";
5085 if(LocationName ==
"")
5087 int FirstNamedElementPos, SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos;
5088 int RearTrainRearPosition, RearTrainFrontPosition, RearTrainExitPos;
5089 int FrontTrainRearPosition, FrontTrainFrontPosition, FrontTrainExitPos;
5093 if(LocationName !=
"")
5101 SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos))
5106 SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos))
5120 int LeadPosA = FirstNamedElementPos;
5121 int LeadPosB = FirstNamedLinkedElementPos;
5122 int LeadPosC = SecondNamedElementPos;
5123 int LeadPosD = SecondNamedLinkedElementPos;
5125 int LeadNumAtLoc = 0;
5134 if(LeadNumAtLoc < 4)
5138 SecondNamedLinkedElementPos))
5140 FirstNamedElementPos = LeadPosA;
5141 FirstNamedLinkedElementPos = LeadPosB;
5142 SecondNamedElementPos = LeadPosC;
5143 SecondNamedLinkedElementPos = LeadPosD;
5147 int MidNumAtLoc = 0;
5156 if(LeadNumAtLoc > MidNumAtLoc)
5159 FirstNamedElementPos = LeadPosA;
5160 FirstNamedLinkedElementPos = LeadPosB;
5161 SecondNamedElementPos = LeadPosC;
5162 SecondNamedLinkedElementPos = LeadPosD;
5175 throw Exception(
"Error - LocationName not set in FrontTrainSplit");
5184 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5185 FrontTrainRearPosition = FirstNamedElementPos;
5186 RearTrainFrontPosition = SecondNamedElementPos;
5187 RearTrainRearPosition = SecondNamedLinkedElementPos;
5191 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5192 FrontTrainRearPosition = SecondNamedElementPos;
5193 RearTrainFrontPosition = FirstNamedElementPos;
5194 RearTrainRearPosition = FirstNamedLinkedElementPos;
5201 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5202 FrontTrainRearPosition = SecondNamedElementPos;
5203 RearTrainFrontPosition = FirstNamedElementPos;
5204 RearTrainRearPosition = FirstNamedLinkedElementPos;
5208 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5209 FrontTrainRearPosition = FirstNamedElementPos;
5210 RearTrainFrontPosition = SecondNamedElementPos;
5211 RearTrainRearPosition = SecondNamedLinkedElementPos;
5214 RearTrainExitPos = -1;
5215 for(
int x = 0; x < 4; x++)
5219 RearTrainExitPos = x;
5223 if(RearTrainExitPos == -1)
5224 throw Exception(
"Error - RearTrainRearPosition not linked to RearTrainFrontPosition in FrontTrainSplit");
5226 FrontTrainExitPos = -1;
5227 for(
int x = 0; x < 4; x++)
5231 FrontTrainExitPos = x;
5235 if(FrontTrainExitPos == -1)
5236 throw Exception(
"Error - FrontTrainRearPosition not linked to FrontTrainFrontPosition in FrontTrainSplit");
5239 int TrainIDOnRearOfRearTrain, TrainIDOnFrontOfRearTrain, TrainIDOnRearOfFrontTrain, TrainIDOnFrontOfFrontTrain;
5244 else if((RearMostElement.
TrackType ==
Bridge) && (RearTrainExitPos < 2))
5258 else if((FrontMostElement.
TrackType ==
Bridge) && (FrontTrainExitPos < 2))
5263 if(((TrainIDOnRearOfRearTrain > -1) && (TrainIDOnRearOfRearTrain !=
TrainID)) || ((TrainIDOnFrontOfRearTrain > -1) && (TrainIDOnFrontOfRearTrain !=
TrainID)
5264 ) || ((TrainIDOnRearOfFrontTrain > -1) && (TrainIDOnRearOfFrontTrain !=
TrainID)) ||
5265 ((TrainIDOnFrontOfFrontTrain > -1) && (TrainIDOnFrontOfFrontTrain !=
TrainID)))
5361 if(LocationName ==
"")
5363 int FirstNamedElementPos, SecondNamedElementPos, FirstNamedLinkedElementPos, SecondNamedLinkedElementPos;
5364 int RearTrainRearPosition, RearTrainFrontPosition, RearTrainExitPos;
5365 int FrontTrainRearPosition, FrontTrainFrontPosition, FrontTrainExitPos;
5369 if(LocationName !=
"")
5376 SecondNamedLinkedElementPos))
5380 SecondNamedLinkedElementPos))
5394 int LeadPosA = FirstNamedElementPos;
5395 int LeadPosB = FirstNamedLinkedElementPos;
5396 int LeadPosC = SecondNamedElementPos;
5397 int LeadPosD = SecondNamedLinkedElementPos;
5399 int LeadNumAtLoc = 0;
5408 if(LeadNumAtLoc < 4)
5412 SecondNamedLinkedElementPos))
5414 FirstNamedElementPos = LeadPosA;
5415 FirstNamedLinkedElementPos = LeadPosB;
5416 SecondNamedElementPos = LeadPosC;
5417 SecondNamedLinkedElementPos = LeadPosD;
5421 int MidNumAtLoc = 0;
5430 if(LeadNumAtLoc > MidNumAtLoc)
5433 FirstNamedElementPos = LeadPosA;
5434 FirstNamedLinkedElementPos = LeadPosB;
5435 SecondNamedElementPos = LeadPosC;
5436 SecondNamedLinkedElementPos = LeadPosD;
5449 throw Exception(
"Error - LocationName not set in RearTrainSplit");
5458 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5459 FrontTrainRearPosition = FirstNamedElementPos;
5460 RearTrainFrontPosition = SecondNamedElementPos;
5461 RearTrainRearPosition = SecondNamedLinkedElementPos;
5465 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5466 FrontTrainRearPosition = SecondNamedElementPos;
5467 RearTrainFrontPosition = FirstNamedElementPos;
5468 RearTrainRearPosition = FirstNamedLinkedElementPos;
5475 FrontTrainFrontPosition = SecondNamedLinkedElementPos;
5476 FrontTrainRearPosition = SecondNamedElementPos;
5477 RearTrainFrontPosition = FirstNamedElementPos;
5478 RearTrainRearPosition = FirstNamedLinkedElementPos;
5482 FrontTrainFrontPosition = FirstNamedLinkedElementPos;
5483 FrontTrainRearPosition = FirstNamedElementPos;
5484 RearTrainFrontPosition = SecondNamedElementPos;
5485 RearTrainRearPosition = SecondNamedLinkedElementPos;
5488 RearTrainExitPos = -1;
5489 for(
int x = 0; x < 4; x++)
5493 RearTrainExitPos = x;
5497 if(RearTrainExitPos == -1)
5498 throw Exception(
"Error - RearTrainRearPosition not linked to RearTrainFrontPosition in RearTrainSplit");
5499 FrontTrainExitPos = -1;
5500 for(
int x = 0; x < 4; x++)
5504 FrontTrainExitPos = x;
5508 if(FrontTrainExitPos == -1)
5509 throw Exception(
"Error - FrontTrainRearPosition not linked to FrontTrainFrontPosition in RearTrainSplit");
5512 int TrainIDOnRearOfRearTrain, TrainIDOnFrontOfRearTrain, TrainIDOnRearOfFrontTrain, TrainIDOnFrontOfFrontTrain;
5517 else if((RearMostElement.
TrackType ==
Bridge) && (RearTrainExitPos < 2))
5531 else if((FrontMostElement.
TrackType ==
Bridge) && (FrontTrainExitPos < 2))
5536 if(((TrainIDOnRearOfRearTrain > -1) && (TrainIDOnRearOfRearTrain !=
TrainID)) || ((TrainIDOnFrontOfRearTrain > -1) && (TrainIDOnFrontOfRearTrain !=
TrainID)
5537 ) || ((TrainIDOnRearOfFrontTrain > -1) && (TrainIDOnRearOfFrontTrain !=
TrainID)) ||
5538 ((TrainIDOnFrontOfFrontTrain > -1) && (TrainIDOnFrontOfFrontTrain !=
TrainID)))
5675 TTrain *TrainToBeJoinedBy;
5706 double OtherBrakeForce = TrainToBeJoinedBy->
MaxBrakeRate * TrainToBeJoinedBy->
Mass;
5708 double CombinedBrakeRate = (OtherBrakeForce + OwnBrakeForce) / (TrainToBeJoinedBy->
Mass +
Mass);
5763 int RouteNumber = -1;
5869 for(
int x = 0; x < IncNum; x++)
5900 else if(Ptr->
Command ==
"jbo")
5911 throw Exception(
"Error - illegal command in SendMissedActionLogs for IncNum = " + AnsiString(IncNum) +
", and command = " + Ptr->
Command);
5917 bool IncludeFER =
false;
5923 if(!IncludeFER && (Ptr->
Command ==
"Fer"))
5928 else if(IncludeFER && (Ptr->
Command ==
"Fer"))
5939 else if(Ptr->
Command ==
"Fjo")
5945 else if(Ptr->
Command ==
"Frh")
5955 else if(Ptr->
Command ==
"Frh-sh")
6006 else if(Ptr->
Command ==
"jbo")
6011 else if(Ptr->
Command ==
"cdt")
6019 throw Exception(
"Error - illegal command in SendMissedActionLogs for IncNum = " + AnsiString(IncNum) +
", and command = " + Ptr->
Command);
6382 int RouteNumber = -1;
6417 ",FloatingLabelNextString" +
"," +
HeadCode);
6418 AnsiString RetStr =
"", LocationName =
"";
6422 throw Exception(
"Error - start entry in FloatingLabelNextString");
6462 else if(Ptr->
Command ==
"Fns")
6468 else if(Ptr->
Command ==
"F-nshs")
6499 RetStr =
"None, train terminated at " + Ptr->
LocationName;
6501 else if(Ptr->
Command ==
"Frh")
6503 RetStr =
"None, train terminated at " + Ptr->
LocationName;
6505 else if(Ptr->
Command ==
"Fer")
6509 else if(Ptr->
Command ==
"Fjo")
6514 else if(Ptr->
Command ==
"jbo")
6519 else if(Ptr->
Command ==
"fsp")
6524 else if(Ptr->
Command ==
"rsp")
6529 else if(Ptr->
Command ==
"cdt")
6542 + AnsiString(RptNum) +
",CheckNewServiceDepartureTime," +
HeadCode);
6543 AnsiString DepTime =
"", EventTime =
"";
6544 bool CDTFlag =
false;
6548 if(AVI->Command ==
"cdt")
6553 if((AVI->Command ==
"fsp") || (AVI->Command ==
"rsp"))
6556 RetStr +=
"\nNew service splits at " + EventTime;
6560 if(AVI->Command ==
"jbo")
6563 RetStr +=
"\nNew service joined by " + AVI->OtherHeadCode +
" at " + EventTime;
6567 if((AVI->FormatType ==
TimeLoc) && (AVI->DepartureTime > TDateTime(-1)))
6572 RetStr +=
"\nNew service changes direction then departs at " + DepTime;
6576 RetStr +=
"\nNew service departs at " + DepTime;
6592 ",FloatingTimetableString" +
"," +
HeadCode);
6593 AnsiString RetStr =
"", PartStr =
"";
6599 throw Exception(
"Error - start entry in FloatingTimetableString");
6602 bool FirstPass =
true;
6613 AnsiString TrainLoc =
"";
6651 AnsiString TrainLoc =
"";
6679 else if(Ptr->
Command ==
"Fns")
6685 else if(Ptr->
Command ==
"F-nshs")
6718 else if(Ptr->
Command ==
"Frh")
6722 else if(Ptr->
Command ==
"Fer")
6726 else if(Ptr->
Command ==
"Fjo")
6731 else if(Ptr->
Command ==
"jbo")
6736 else if(Ptr->
Command ==
"fsp")
6741 else if(Ptr->
Command ==
"rsp")
6746 else if(Ptr->
Command ==
"cdt")
6751 RetStr = RetStr +
'\n' + PartStr;
6764 RetStr =
"Timetable finished";
6766 RetStr =
"No timetable";
6892 bool ForwardHeadCode;
6896 ForwardHeadCode =
true;
6901 ForwardHeadCode =
false;
7034 if(ColourNumber == 0)
7036 else if(ColourNumber == 1)
7038 else if(ColourNumber == 2)
7040 else if(ColourNumber == 3)
7042 else if(ColourNumber == 4)
7044 else if(ColourNumber == 5)
7046 else if(ColourNumber == 6)
7048 else if(ColourNumber == 7)
7050 else if(ColourNumber == 8)
7052 else if(ColourNumber == 9)
7054 else if(ColourNumber == 10)
7056 else if(ColourNumber == 11)
7058 else if(ColourNumber == 12)
7060 else if(ColourNumber == 13)
7062 else if(ColourNumber == 14)
7072 for(
int x = 0; x < 4; x++)
7079 for(
int x = 0; x < 4; x++)
7144 if((LocationAndMarker[1] !=
'*') && (LocationAndMarker.Length() > 6))
7147 AnsiString Location = LocationAndMarker.SubString(1, LocationAndMarker.Length() - 6);
7148 bool GiveMessagesFalse =
false;
7149 bool CheckLocationsExistInRailwayTrue =
true;
7155 AnsiString Marker = LocationAndMarker.SubString(LocationAndMarker.Length() - 5, 6);
7158 if(Marker[6] ==
'1')
7455 bool HideFlashingTrain =
true;
7458 Graphics::TBitmap *SmallTrainBitmap;
7499 HideFlashingTrain =
false;
7504 HideFlashingTrain =
false;
7509 HideFlashingTrain =
false;
7514 HideFlashingTrain =
false;
7519 HideFlashingTrain =
false;
7524 if((
LeadElement > -1) && (!HideFlashingTrain || Flash))
7528 if((
MidElement > -1) && (!HideFlashingTrain || Flash))
7552 for(
int y = 0; y < 3; y++)
7556 bool FoundFlag =
false;
7567 if(IMPair.first != IMPair.second)
7594 if((LocationName ==
"") && (
MidElement > -1))
7598 if((LocationName ==
"") && (
LagElement > -1))
7602 if(LocationName ==
"")
7604 throw Exception(
"Error - Location name not set in TrainAtLocation");
7615 for(
int x = 0; x < 4; x++)
7627 for(
int x = 0; x < 4; x++)
7644 AnsiString(LinkNumber) +
"," +
HeadCode);
7695 int DistanceToRedSignal = 0;
7696 float TimeToAct = 0;
7738 float CurrentStopTime;
7739 float LaterStopTime;
7740 float RecoverableTime;
7745 if(DistanceToRedSignal == -1)
7764 float TimeToSubtract, TotalStopTime;
7766 TimeToSubtract = RecoverableTime;
7772 if(CurrentStopTime > 0)
7773 TotalStopTime = CurrentStopTime + LaterStopTime;
7781 if(LaterStopTime == 0)
7782 TotalStopTime = CurrentStopTime;
7786 TotalStopTime = CurrentStopTime + LaterStopTime - TimeToSubtract;
7789 if(AvTrackSpeed < 30)
7791 int Speed = AvTrackSpeed;
7799 TimeToAct = TotalStopTime + DistanceToRedSignal * 3.6 / 60 / Speed;
7819 if((NextEntryPos == 0) || (NextEntryPos == 2))
7931 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
7972 int IncrementalMinutes = 0;
7973 int IncrementalDigits = 0;
7981 throw Exception(
"Error - Repeat entry && less than two trains for Snt entry: " + TDEntry.
HeadCode);
8007 if(AVEntry0.
Command ==
"Snt-sh")
8012 int IncrementalMinutes = 0;
8013 int IncrementalDigits = 0;
8021 throw Exception(
"Error - Repeat entry && less than two trains for Snt-sh entry: " + TDEntry.
HeadCode);
8054 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8114 AnsiString Loc =
"";
8115 bool ElementFound =
false;
8120 ElementFound =
true;
8125 ElementFound =
true;
8130 ElementFound =
true;
8160 else if(AVEntryPtr->
Command ==
"Fer")
8162 bool CorrectExit =
false;
8270 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8285 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8300 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8311 bool TTrainController::AddTrain(
int Caller,
int RearPosition,
int FrontPosition, AnsiString HeadCode,
int StartSpeed,
int Mass,
double MaxRunningSpeed,
8312 double MaxBrakeRate,
double PowerAtRail, AnsiString ModeStr,
TTrainDataEntry *TrainDataEntryPtr,
int RepeatNumber,
int IncrementalMinutes,
8313 int IncrementalDigits,
int SignallerSpeed,
bool SignallerControl,
TActionEventType &EventType)
8315 LogEvent(AnsiString(Caller) +
",AddTrain," + AnsiString(RearPosition) +
"," + AnsiString(FrontPosition) +
"," + HeadCode +
"," + AnsiString(StartSpeed) +
8316 "," + AnsiString(Mass) +
"," + ModeStr);
8318 "," + HeadCode +
"," + AnsiString(StartSpeed) +
"," + AnsiString(Mass) +
"," + ModeStr +
"," + HeadCode);
8320 int RearExitPos = -1;
8322 for(
int x = 0; x < 4; x++)
8329 if(RearExitPos == -1)
8331 throw Exception(
"Error, RearExit == -1 in AddTrain");
8334 bool ReportFlag =
true;
8350 if(ModeStr ==
"Timetable")
8354 if(MaxRunningSpeed < 10)
8356 MaxRunningSpeed = 10;
8358 if(SignallerSpeed < 10)
8359 SignallerSpeed = 10;
8360 TTrain *NewTrain =
new TTrain(0, RearPosition, RearExitPos, HeadCode, StartSpeed, Mass, MaxRunningSpeed, MaxBrakeRate, PowerAtRail, TrainMode,
8361 TrainDataEntryPtr, RepeatNumber, IncrementalMinutes, IncrementalDigits, SignallerSpeed);
8366 if(SignallerControl)
8397 if(!SignallerControl)
8412 if(!SignallerControl)
8423 AnsiString Loc =
"";
8440 if(!SignallerControl)
8461 int RouteNumber = -1;
8462 bool SignalsSet =
false;
8468 int RouteStartPosition;
8472 if(FirstPair.first == RouteNumber)
8474 RouteStartPosition = FirstPair.second;
8476 else if(SecondPair.first == RouteNumber)
8478 RouteStartPosition = SecondPair.second;
8482 throw Exception(
"Error, RouteNumber not found in Route2MultiMap in 1st of 2 calls to SetAllRearwardsSignals in AddTrain");
8488 else if(RouteNumber > -1)
8508 int LinkedRouteNumber = -1;
8527 int RouteStartPosition;
8531 if(FirstPair.first == RouteNumber)
8533 RouteStartPosition = FirstPair.second;
8535 else if(SecondPair.first == RouteNumber)
8537 RouteStartPosition = SecondPair.second;
8541 throw Exception(
"Error, RouteNumber not found in Route2MultiMap in 2nd of 2 calls to SetAllRearwardsSignals in AddTrain");
8547 else if(RouteNumber > -1)
8567 int LinkedRouteNumber = -1;
8589 AnsiString(TrackVectorNumber));
8592 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8601 throw Exception(
"Error, VecPos not set in EntryPos");
8603 if(
TrainVectorAt(2, VecPos).LeadElement == TrackVectorNumber)
8608 else if(
TrainVectorAt(4, VecPos).MidElement == TrackVectorNumber)
8613 else if(
TrainVectorAt(6, VecPos).LagElement == TrackVectorNumber)
8627 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8635 throw Exception(
"Error - No Train identified in TrainVectorAtIdent with ID = " + AnsiString(TrainID));
8645 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
8675 AnsiString RetStr =
"", PartStr =
"";
8683 if((Ptr->Command !=
"") && (Ptr->Command[1] ==
'S'))
8689 if(Ptr->SignallerControl)
8691 RetStr =
"Train under signaller control";
8696 if(Ptr->ArrivalTime == Ptr->DepartureTime)
8707 else if((Ptr->FormatType ==
TimeLoc) && (Ptr->ArrivalTime != TDateTime(-1)))
8711 else if((Ptr->FormatType ==
TimeLoc) && (Ptr->ArrivalTime == TDateTime(-1)))
8715 else if(Ptr->FormatType ==
PassTime)
8719 else if(Ptr->Command ==
"Fns")
8725 else if(Ptr->Command ==
"F-nshs")
8728 Ptr->NonRepeatingShuttleLinkHeadCode +
" at " + Ptr->LocationName;
8735 else if((Ptr->Command ==
"Fns-sh") && (RepNum < (TTDEPtr->
NumberOfTrains - 1)))
8742 else if((Ptr->Command ==
"Fns-sh") && (RepNum >= (TTDEPtr->
NumberOfTrains - 1)))
8745 Ptr->NonRepeatingShuttleLinkHeadCode, +
" at " + Ptr->LocationName;
8748 else if((Ptr->Command ==
"Frh-sh") && (RepNum < (TTDEPtr->
NumberOfTrains - 1)))
8755 else if((Ptr->Command ==
"Frh-sh") && (RepNum >= (TTDEPtr->
NumberOfTrains - 1)))
8757 PartStr =
"Terminate at " + Ptr->LocationName;
8759 else if(Ptr->Command ==
"Frh")
8761 PartStr =
"Terminate at " + Ptr->LocationName;
8763 else if(Ptr->Command ==
"Fer")
8768 else if(Ptr->Command ==
"Fjo")
8771 Ptr->OtherHeadCode, RepNum, IncDig) +
" at " + Ptr->LocationName;
8773 else if(Ptr->Command ==
"jbo")
8776 (50, Ptr->OtherHeadCode, RepNum, IncDig) +
" at " + Ptr->LocationName;
8778 else if(Ptr->Command ==
"fsp")
8783 else if(Ptr->Command ==
"rsp")
8788 else if(Ptr->Command ==
"cdt")
8793 RetStr = RetStr +
'\n' + PartStr;
8798 while(Ptr < TTDEPtr->ActionVector.end() && (Count < 33) && ((Ptr->Command ==
"") || ((Ptr->Command !=
"") && (Ptr->Command[1] !=
'F'))));
8811 + AnsiString(RptNum) +
",ControllerCheckNewServiceDepartureTime," + TDEPtr->
HeadCode);
8812 AnsiString DepTime =
"", EventTime =
"";
8813 bool CDTFlag =
false;
8817 if(AVI->Command ==
"cdt")
8822 if((AVI->Command ==
"fsp") || (AVI->Command ==
"rsp"))
8825 RetStr +=
"\nNew service splits at " + EventTime;
8829 if(AVI->Command ==
"jbo")
8832 RetStr +=
"\nNew service joined by " + AVI->OtherHeadCode +
" at " + EventTime;
8836 if((AVI->FormatType ==
TimeLoc) && (AVI->DepartureTime > TDateTime(-1)))
8841 RetStr +=
"\nNew service changes direction then departs at " + DepTime;
8845 RetStr +=
"\nNew service departs at " + DepTime;
9003 ActiveTrackElementNameMapEntry.first =
Track->
TrackVector.at(x).ActiveTrackElementName;
9004 ActiveTrackElementNameMapEntry.second = 0;
9010 std::ifstream TTBLFile(FileName, std::ios_base::binary);
9013 if(TTBLFile.is_open())
9015 char *TrainTimetableString =
new char[10000];
9017 bool EndOfFile =
false;
9020 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
9022 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
9028 delete TrainTimetableString;
9032 AnsiString OneLine(TrainTimetableString);
9033 bool FinalCallFalse =
false;
9034 while((Count == 0) && !
ProcessOneTimetableLine(5, Count, OneLine, EndOfFile, FinalCallFalse, GiveMessages, CheckLocationsExistInRailway))
9038 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
9039 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
9043 TimetableMessage(GiveMessages,
"Timetable invalid - unable to find a valid start time on its own line");
9045 delete TrainTimetableString;
9049 OneLine = AnsiString(TrainTimetableString);
9055 TTBLFile.getline(TrainTimetableString, 10000,
'\0');
9057 if(TTBLFile.eof() && (TrainTimetableString[0] ==
'\0'))
9065 OneLine = AnsiString(TrainTimetableString);
9066 if(OneLine.Length() > 9999)
9068 TimetableMessage(GiveMessages,
"Timetable contains a line that is too long - 10,000 or more characters!");
9070 delete TrainTimetableString;
9074 bool FinalCallFalse =
false;
9075 if(!
ProcessOneTimetableLine(6, Count, OneLine, EndOfFile, FinalCallFalse, GiveMessages, CheckLocationsExistInRailway))
9079 delete TrainTimetableString;
9083 if(EndOfFile && (Count < 2))
9086 TimetableMessage(GiveMessages,
"Timetable has too few or no relevant entries - must have a start time on its own line and at least one train");
9088 delete TrainTimetableString;
9094 delete TrainTimetableString;
9099 TimetableMessage(GiveMessages,
"Failed to open timetable file, make sure it's not open in another application");
9110 bool CheckLocationsExistInRailway)
9235 AnsiString((
short)FinalCall) +
"," + AnsiString((
short)CheckLocationsExistInRailway));
9245 if(OneLine[1] !=
'*')
9247 int SCPos = OneLine.Pos(
';');
9254 bool AllCommas =
true;
9256 for(
int x = 1; x < OneLine.Length() + 1; x++)
9258 if(OneLine[x] !=
',')
9261 if(AllCommas || (OneLine ==
""))
9276 AnsiString First =
"", Second =
"", Third =
"", Fourth =
"";
9277 int RearStartOrRepeatMins = 0, FrontStartOrRepeatDigits = 0, NumberOfRepeats = 0;
9278 TDateTime EventTime(0), ArrivalTime(0), DepartureTime(0);
9279 TDateTime StartTime(0);
9281 bool Warning =
false;
9308 AnsiString TrainInfoStr =
"", HeadCode =
"", Description =
"";
9309 int StartSpeed = 0, MaxRunningSpeed = 0, Mass = 0;
9310 double MaxBrakeRate = 0;
9311 double PowerAtRail = 0;
9312 int SignallerSpeed = 0;
9313 if(OneLine[1] ==
'*')
9319 int Pos = OneLine.Pos(
',');
9322 int SubStringLength = 20;
9323 if(OneLine.Length() < 20)
9324 SubStringLength = OneLine.Length();
9325 TimetableMessage(GiveMessages,
"Error in timetable - entry incomplete: see '" + OneLine.SubString(1, SubStringLength) +
"'....");
9329 TrainInfoStr = OneLine.SubString(1, Pos - 1);
9330 if(!
SplitTrainInfo(0, TrainInfoStr, HeadCode, Description, StartSpeed, MaxRunningSpeed, Mass, MaxBrakeRate, PowerAtRail, SignallerSpeed,
9340 TempTrainDataEntry.
HeadCode = HeadCode;
9344 TempTrainDataEntry.
Mass = Mass;
9352 AnsiString NewRemainder = OneLine.SubString(Pos + 1, OneLine.Length() - Pos);
9355 while(NewRemainder[NewRemainder.Length()] ==
',')
9357 if(NewRemainder.Length() > 1)
9359 NewRemainder = NewRemainder.SubString(1, NewRemainder.Length() - 1);
9368 if(NewRemainder ==
"")
9370 TimetableMessage(GiveMessages,
"Error in timetable - no events following train: '" + OneLine +
"'");
9376 for(
int x = 1; x < NewRemainder.Length() + 1; x++)
9378 if(NewRemainder[x] ==
',')
9383 if((NewRemainder.SubString(7, 3) !=
"Snt") || (NewRemainder[NewRemainder.Length()] !=
'S'))
9385 int SubStringLength = 20;
9386 if(OneLine.Length() < 20)
9387 SubStringLength = OneLine.Length();
9389 "Error in timetable - must have at least a start and a finish event for a train that is not started under signaller control - see line beginning: '" +
9390 OneLine.SubString(1, SubStringLength) +
"'....");
9395 AnsiString OneEntry =
"";
9400 bool FinishFlag =
false;
9401 for(
int x = 0; x < CommaCount + 1; x++)
9403 if((CommaCount == 0) || (x < CommaCount))
9410 OneEntry = NewRemainder;
9415 Pos = NewRemainder.Pos(
',');
9416 OneEntry = NewRemainder.SubString(1, Pos - 1);
9417 NewRemainder = NewRemainder.SubString(Pos + 1, NewRemainder.Length() - Pos);
9423 RearStartOrRepeatMins = 0;
9424 FrontStartOrRepeatDigits = 0;
9425 NumberOfRepeats = 0;
9426 if(!
SplitEntry(0, OneEntry, GiveMessages, CheckLocationsExistInRailway, First, Second, Third, Fourth, RearStartOrRepeatMins,
9427 FrontStartOrRepeatDigits, FormatType, LocationType, SequenceType, ShuttleLinkType, ExitList, Warning))
9429 TimetableMessage(GiveMessages,
"Error in timetable - Event: '" + OneEntry +
"'");
9434 if(Warning && (Second ==
"Frh"))
9436 TimetableMessage(GiveMessages,
"Error in line - '" + OneEntry +
"': warnings cannot be given for 'Frh' events");
9440 if(Warning && (Second ==
"Fjo"))
9443 "': warnings cannot be given for 'Fjo' events, for a train join warning add a 'W' prefix to the 'jbo' event");
9449 if(SequenceType !=
Start)
9451 TimetableMessage(GiveMessages,
"Error in timetable - First event not a start event: '" + OneEntry +
"'");
9455 if((Second ==
"Snt") && (Fourth ==
'S') && (NewRemainder !=
""))
9457 if(NewRemainder[1] !=
'R')
9460 "Error in timetable - the only event that can follow a train created under signaller control is a repeat, see '" +
9466 if((Second ==
"Snt") || (Second ==
"Snt-sh"))
9470 if((HeadCode ==
"") || (Description ==
"") || (MaxRunningSpeed == 0) || (Mass == 0) || (MaxBrakeRate == 0))
9473 TimetableMessage(GiveMessages,
"Error in timetable - train information incomplete before 'Snt' or 'Snt-sh' start event: '" +
9479 if((Second ==
"Sfs") || (Second ==
"Sns") || (Second ==
"Sns-sh") || (Second ==
"Sns-fsh"))
9484 TimetableMessage(GiveMessages,
"Error in timetable - headcode missing before 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' start event: '" +
9489 if((StartSpeed != 0) || (MaxRunningSpeed != 0) || (Mass != 0) || (MaxBrakeRate != 0) || (PowerAtRail != 0))
9492 "Error in timetable - information additional to a headcode & optional description given before 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' start event: '" +
9499 if(SequenceType ==
Finish)
9514 ActionVectorEntry.
Warning = Warning;
9527 ActionVectorEntry.
Command = Second;
9540 else if(FormatType ==
TimeCmd)
9545 ActionVectorEntry.
Command = Second;
9552 ActionVectorEntry.
Command = Second;
9553 ActionVectorEntry.
ExitList = ExitList;
9560 ActionVectorEntry.
Command = Second;
9571 ActionVectorEntry.
Command = Second;
9581 ActionVectorEntry.
Command = Second;
9590 ActionVectorEntry.
Command = Second;
9598 ActionVectorEntry.
Command = Second;
9606 ActionVectorEntry.
Command = Second;
9612 ActionVectorEntry.
Command = Second;
9614 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
9619 OneEntry = NewRemainder;
9624 RearStartOrRepeatMins = 0;
9625 FrontStartOrRepeatDigits = 0;
9626 NumberOfRepeats = 0;
9627 if((FinishFlag) && (OneEntry[1] !=
'R'))
9630 TimetableMessage(GiveMessages,
"Error in timetable - Last event = '" + OneEntry +
"'. An earlier finish event has been found with something other than a repeat following it - only a repeat can follow a finish event.");
9634 if(OneEntry[1] !=
'R')
9636 if(!
SplitEntry(1, OneEntry, GiveMessages, CheckLocationsExistInRailway, First, Second, Third, Fourth, RearStartOrRepeatMins,
9637 FrontStartOrRepeatDigits, FormatType, LocationType, SequenceType, ShuttleLinkType, ExitList, Warning))
9639 TimetableMessage(GiveMessages,
"Error in timetable - Event: '" + OneEntry +
"'");
9643 if(SequenceType !=
Finish)
9645 TimetableMessage(GiveMessages,
"Error in timetable - last event should be a finish: '" + OneEntry +
"'");
9658 ActionVectorEntry.
Warning = Warning;
9664 ActionVectorEntry.
Command = Second;
9671 ActionVectorEntry.
Command = Second;
9679 ActionVectorEntry.
Command = Second;
9687 ActionVectorEntry.
Command = Second;
9696 ActionVectorEntry.
Command = Second;
9697 ActionVectorEntry.
ExitList = ExitList;
9701 ActionVectorEntry.
Command = Second;
9703 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
9708 if(!
SplitRepeat(0, OneEntry, RearStartOrRepeatMins, FrontStartOrRepeatDigits, NumberOfRepeats, GiveMessages))
9724 TempTrainDataEntry.
ActionVector.push_back(ActionVectorEntry);
9743 if((HeadCode[HeadCode.Length() - 1] <
'0') || (HeadCode[HeadCode.Length() - 1] >
'9'))
9748 if((HeadCode[HeadCode.Length()] <
'0') || (HeadCode[HeadCode.Length()] >
'9'))
9763 if(TimeStr.Length() < 5)
9768 if((TimeStr[1] <
'0') || (TimeStr[1] >
'9'))
9773 if((TimeStr[2] <
'0') || (TimeStr[2] >
'9'))
9778 if(TimeStr[3] !=
':')
9783 if((TimeStr[4] <
'0') || (TimeStr[4] >
'5'))
9788 if((TimeStr[5] <
'0') || (TimeStr[5] >
'9'))
9793 while(TimeStr.Length() > 5)
9794 TimeStr = TimeStr.SubString(1, TimeStr.Length() - 1);
9795 double WholeHours = (AnsiString(TimeStr[1]) + AnsiString(TimeStr[2])).ToDouble();
9796 double FracHour = ((AnsiString(TimeStr[4]) + AnsiString(TimeStr[5])).ToDouble()) / 60.0;
9798 if((WholeHours + FracHour) >= 95.98334)
9803 Time = TDateTime((WholeHours + FracHour) / 24);
9810 bool TTrainController::SplitEntry(
int Caller, AnsiString OneEntry,
bool GiveMessages,
bool CheckLocationsExistInRailway, AnsiString &First, AnsiString &Second,
9811 AnsiString &Third, AnsiString &Fourth,
int &RearStartOrRepeatMins,
int &FrontStartOrRepeatDigits,
TTimetableFormatType &FormatType,
9822 if(OneEntry.Length() > 0)
9824 if(OneEntry[1] ==
'W')
9827 OneEntry = OneEntry.SubString(2, OneEntry.Length() - 1);
9831 if(OneEntry ==
"Frh")
9841 if(OneEntry.Length() < 7)
9846 int Pos = OneEntry.Pos(
';');
9854 First = OneEntry.SubString(1, 5);
9860 AnsiString Remainder = OneEntry.SubString(Pos + 1, OneEntry.Length() - Pos);
9862 if((Remainder[1] >=
'0') && (Remainder[1] <=
'9'))
9865 if(Remainder.Length() < 7)
9870 Pos = Remainder.Pos(
';');
9877 Second = Remainder.SubString(1, 5);
9883 Third = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
9896 Pos = Remainder.Pos(
';');
9925 if((Pos != 4) && (Pos != 7) && (Pos != 8))
9931 Second = Remainder.SubString(1, Pos - 1);
9933 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
9935 Pos = Remainder.Pos(
';');
9940 Third = Remainder.SubString(1, Pos - 1);
9941 Fourth = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
9943 if((Second ==
"Snt") || (Second ==
"Snt-sh"))
9946 int SpacePos = Third.Pos(
' ');
9952 AnsiString RearStartStr = Third.SubString(1, SpacePos - 1);
9953 AnsiString FrontStartStr = Third.SubString(SpacePos + 1, Third.Length() - SpacePos);
9955 if(CheckLocationsExistInRailway)
9968 SequenceType =
Start;
9977 SequenceType =
Start;
9989 if(Second ==
"Sns-sh")
9993 SequenceType =
Start;
10009 if(Second ==
"F-nshs")
10024 if(Second ==
"Sns-fsh")
10028 SequenceType =
Start;
10039 if(Second ==
"Fns-sh")
10060 if(Second ==
"pas")
10076 if(Second ==
"Fer")
10083 if(CheckLocationsExistInRailway)
10096 if((Second !=
"Fns") && (Second !=
"Fjo") && (Second !=
"jbo") && (Second !=
"fsp") && (Second !=
"rsp") && (Second !=
"Sfs") && (Second !=
"Sns") &&
10097 (Second !=
"Frh-sh"))
10110 if(Second ==
"Frh-sh")
10114 if((Second ==
"Fns") || (Second ==
"Fjo") || (Second ==
"Frh-sh"))
10118 if((Second ==
"jbo") || (Second ==
"fsp") || (Second ==
"rsp"))
10122 if((Second ==
"Sfs") || (Second ==
"Sns"))
10124 SequenceType =
Start;
10142 if((LocStr[1] >=
'0') && (LocStr[1] <=
'9'))
10147 for(
int x = 1; x < LocStr.Length() + 1; x++)
10149 if(LocStr[x] <
' ')
10154 if(LocStr[x] >
'z')
10161 if(CheckLocationsExistInRailway)
10166 "' appears in the timetable but is not a valid name. To be valid the name must apply to one or more platforms (not concourses on their own), or to track at a blue non-station named location other than a continuation.");
10184 if((HeadCode.Length() < 4) || (HeadCode.Length() > 8))
10187 "', length must be between 4 and 8 characters, and last 4 must be a legitimate headcode. This error can also be caused by omitting a service reference after Snt-sh, Sns-sh, Fns-sh or Frh-sh");
10192 for(
int x = 1; x < (HeadCode.Length() + 1); x++)
10194 if((HeadCode[x] <
' ') || (HeadCode[x] >
'~'))
10196 TimetableMessage(GiveMessages,
"Non-printable character in headcode '" + HeadCode +
"'");
10202 for(
int x = 3; x >= 0; x--)
10204 if(((HeadCode[HeadCode.Length() - x] <
'A') || (HeadCode[HeadCode.Length() - x] >
'Z')) && ((HeadCode[HeadCode.Length() - x] <
'a') ||
10205 (HeadCode[HeadCode.Length() - x] >
'z')) && ((HeadCode[HeadCode.Length() - x] <
'0') || (HeadCode[HeadCode.Length() - x] >
'9')))
10207 TimetableMessage(GiveMessages,
"Headcode error in '" + HeadCode +
"', headcode must consist of letters and digits only");
10223 AnsiString CurrentID =
"";
10225 if(IDSet.Length() == 0)
10227 TimetableMessage(GiveMessages,
"Must have at least one exit element ID following 'Fer'");
10231 for(
int x = 1; x <= IDSet.Length(); x++)
10234 if(((C <
'0') || (C >
'9')) && (C !=
' ') && (C !=
'N') && (C !=
'-'))
10236 TimetableMessage(GiveMessages,
"Illegal character in the set of element IDs following 'Fer' in '" + IDSet +
"'");
10241 int Pos = IDSet.Pos(
' ');
10252 CurrentID = IDSet.SubString(1, Pos - 1);
10253 IDSet = IDSet.SubString(Pos + 1, IDSet.Length() - Pos);
10265 TimetableMessage(GiveMessages,
"The element ID '" + CurrentID +
"' following 'Fer' is not an exit");
10272 if(!ExitList.empty())
10276 if(*ELIT == VecPos)
10278 TimetableMessage(GiveMessages,
"The element ID '" + CurrentID +
"' following 'Fer' duplicates an earlier element");
10285 ExitList.push_back(VecPos);
10295 Pos = IDSet.Pos(
' ');
10302 int &Mass,
double &MaxBrakeRate,
double &PowerAtRail,
int &SignallerSpeed,
bool GiveMessages)
10309 AnsiString Remainder =
"";
10310 int SemiColonCount = 0;
10312 for(
int x = 1; x < TrainInfoStr.Length() + 1; x++)
10314 if(TrainInfoStr[x] ==
';')
10317 if((SemiColonCount != 6) && (SemiColonCount != 7) && (SemiColonCount != 1) && (SemiColonCount != 0))
10319 TimetableMessage(GiveMessages,
"Error in train information in '" + TrainInfoStr +
10320 "'. Should be headcode + optional description for a continuing service;" +
10321 " or headcode, description, start speed, max running speed, mass, brake force, power (and optional signaller max. speed) for a new service");
10325 if(SemiColonCount == 0)
10327 HeadCode = TrainInfoStr;
10336 if(SemiColonCount == 1)
10338 Pos = TrainInfoStr.Pos(
';');
10339 HeadCode = TrainInfoStr.SubString(1, Pos - 1);
10340 Description = TrainInfoStr.SubString(Pos + 1, TrainInfoStr.Length() - Pos);
10346 if(Description ==
"")
10348 TimetableMessage(GiveMessages,
"Train description missing in '" + TrainInfoStr +
"'");
10352 if(Description.Length() > 60)
10354 TimetableMessage(GiveMessages,
"Train description too long, limit of 60 characters '" + TrainInfoStr +
"'");
10358 for(
int x = 1; x < Description.Length() + 1; x++)
10360 if((Description[x] <
' ') || (Description[x] >
'~'))
10362 TimetableMessage(GiveMessages,
"Train description contains invalid characters in '" + TrainInfoStr +
"'");
10371 Pos = TrainInfoStr.Pos(
';');
10372 HeadCode = TrainInfoStr.SubString(1, Pos - 1);
10373 Remainder = TrainInfoStr.SubString(Pos + 1, TrainInfoStr.Length() - Pos);
10379 Pos = Remainder.Pos(
';');
10380 Description = Remainder.SubString(1, Pos - 1);
10381 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10382 if(Description ==
"")
10384 TimetableMessage(GiveMessages,
"Train description missing in '" + TrainInfoStr +
"'");
10388 if(Description.Length() > 60)
10390 TimetableMessage(GiveMessages,
"Train description too long, limit of 60 characters '" + TrainInfoStr +
"'");
10394 for(
int x = 1; x < Description.Length() + 1; x++)
10396 if((Description[x] <
' ') || (Description[x] > 126))
10398 TimetableMessage(GiveMessages,
"Train description contains invalid characters in '" + TrainInfoStr +
"'");
10403 Pos = Remainder.Pos(
';');
10404 AnsiString StartSpeedStr = Remainder.SubString(1, Pos - 1);
10406 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10407 if(StartSpeedStr ==
"")
10409 TimetableMessage(GiveMessages,
"Train starting speed missing in '" + TrainInfoStr +
"'");
10413 for(
int x = 1; x < StartSpeedStr.Length() + 1; x++)
10415 if((StartSpeedStr[x] <
'0') || (StartSpeedStr[x] >
'9'))
10417 TimetableMessage(GiveMessages,
"Train start speed contains invalid characters in '" + TrainInfoStr +
"'");
10422 StartSpeed = StartSpeedStr.ToInt();
10428 TimetableMessage(GiveMessages,
"Train starting speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
10432 Pos = Remainder.Pos(
';');
10433 AnsiString MaxRunningSpeedStr = Remainder.SubString(1, Pos - 1);
10435 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10436 if(MaxRunningSpeedStr ==
"")
10438 TimetableMessage(GiveMessages,
"Train maximum running speed missing in '" + TrainInfoStr +
"'");
10442 for(
int x = 1; x < MaxRunningSpeedStr.Length() + 1; x++)
10444 if((MaxRunningSpeedStr[x] <
'0') || (MaxRunningSpeedStr[x] >
'9'))
10446 TimetableMessage(GiveMessages,
"Train maximum running speed contains invalid characters in '" + TrainInfoStr +
"'");
10451 MaxRunningSpeed = MaxRunningSpeedStr.ToInt();
10457 TimetableMessage(GiveMessages,
"Train maximum running speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
10461 if(MaxRunningSpeed < 10)
10464 MaxRunningSpeed = 10;
10467 TimetableMessage(GiveMessages,
"Train maximum running speed can't be less than 10km/h in '" + TrainInfoStr +
"', it will be set to 10km/h");
10471 Pos = Remainder.Pos(
';');
10472 AnsiString MassStr = Remainder.SubString(1, Pos - 1);
10474 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10477 TimetableMessage(GiveMessages,
"Train mass missing in '" + TrainInfoStr +
"'");
10481 for(
int x = 1; x < MassStr.Length() + 1; x++)
10483 if((MassStr[x] <
'0') || (MassStr[x] >
'9'))
10485 TimetableMessage(GiveMessages,
"Train mass contains invalid characters in '" + TrainInfoStr +
"'");
10490 Mass = MassStr.ToInt() * 1000;
10496 TimetableMessage(GiveMessages,
"Train mass > 10,000 tonnes in '" + TrainInfoStr +
"'. Setting it to 10,000 tonnes");
10502 TimetableMessage(GiveMessages,
"Train mass zero in '" + TrainInfoStr +
"'");
10506 Pos = Remainder.Pos(
';');
10507 AnsiString MaxBrakeForceStr = Remainder.SubString(1, Pos - 1);
10509 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10510 if(MaxBrakeForceStr ==
"")
10512 TimetableMessage(GiveMessages,
"Train braking force missing in '" + TrainInfoStr +
"'");
10516 for(
int x = 1; x < (MaxBrakeForceStr.Length() + 1); x++)
10518 if((MaxBrakeForceStr[x] !=
'.') && ((MaxBrakeForceStr[x] <
'0') || (MaxBrakeForceStr[x] >
'9')))
10520 TimetableMessage(GiveMessages,
"Train braking force contains invalid characters in '" + TrainInfoStr +
"'");
10525 double MaxBrakeForce = MaxBrakeForceStr.ToDouble() * 1000;
10528 if((MaxBrakeForce / Mass) > 1)
10530 MaxBrakeForce = Mass;
10533 TimetableMessage(GiveMessages,
"Train braking force too high in '" + TrainInfoStr +
"'. Setting it to the same as the train mass");
10537 if((MaxBrakeForce / Mass) < 0.01)
10539 MaxBrakeForce = Mass * 0.01;
10542 TimetableMessage(GiveMessages,
"Train braking force too low in '" + TrainInfoStr +
"'. Setting it to 1% of the train mass");
10547 MaxBrakeRate = MaxBrakeForce / Mass * 9.81;
10549 AnsiString GrossPowerStr =
"", SignallerSpeedStr =
"";
10551 if(SemiColonCount == 6)
10553 GrossPowerStr = Remainder;
10554 SignallerSpeedStr =
"30";
10558 Pos = Remainder.Pos(
';');
10559 GrossPowerStr = Remainder.SubString(1, Pos - 1);
10560 SignallerSpeedStr = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10563 if(GrossPowerStr ==
"")
10565 TimetableMessage(GiveMessages,
"Train power missing in '" + TrainInfoStr +
"'");
10569 for(
int x = 1; x < GrossPowerStr.Length() + 1; x++)
10571 if((GrossPowerStr[x] <
'0') || (GrossPowerStr[x] >
'9'))
10573 TimetableMessage(GiveMessages,
"Train power contains invalid characters in '" + TrainInfoStr +
"'");
10579 double GrossPower = GrossPowerStr.ToInt() * 1000;
10586 TimetableMessage(GiveMessages,
"Train power > 100,000kW in '" + TrainInfoStr +
"'. Setting it to 100,000kW");
10590 else if(GrossPower == 0)
10595 else if((GrossPower > 0) && (GrossPower < 10000))
10598 GrossPower = 10000;
10600 PowerAtRail = GrossPower * 0.8;
10604 if(SignallerSpeedStr ==
"")
10606 TimetableMessage(GiveMessages,
"Signaller speed not set in '" + TrainInfoStr +
"', either set a value or remove the extra semicolon");
10610 for(
int x = 1; x < SignallerSpeedStr.Length() + 1; x++)
10612 if((SignallerSpeedStr[x] <
'0') || (SignallerSpeedStr[x] >
'9'))
10614 TimetableMessage(GiveMessages,
"Signaller speed contains invalid characters in '" + TrainInfoStr +
"'");
10619 SignallerSpeed = SignallerSpeedStr.ToInt();
10625 TimetableMessage(GiveMessages,
"Signaller speed > 400km/h in '" + TrainInfoStr +
"'. Setting it to 400km/h");
10629 if(SignallerSpeed < 10)
10632 SignallerSpeed = 10;
10635 TimetableMessage(GiveMessages,
"Signaller speed can't be less than 10km/h in '" + TrainInfoStr +
"', it will be set to 10km/h");
10653 if(OneEntry.Length() < 7)
10655 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
10659 int SemiColonCount = 0;
10661 for(
int x = 1; x < OneEntry.Length() + 1; x++)
10663 if(OneEntry[x] ==
';')
10666 if(SemiColonCount != 3)
10668 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
10672 if((OneEntry[1] !=
'R') || (OneEntry[2] !=
';'))
10674 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - should be 'R;m;d;n'");
10678 AnsiString Remainder = OneEntry.SubString(3, OneEntry.Length() - 2);
10683 Pos = Remainder.Pos(
';');
10684 AnsiString MinutesStr = Remainder.SubString(1, Pos - 1);
10686 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10687 if(MinutesStr ==
"")
10689 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - minute increment segment missing");
10693 if(MinutesStr.Length() > 3)
10696 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - minute value too high, maximum value is 999");
10700 for(
int x = 1; x < MinutesStr.Length() + 1; x++)
10702 if((MinutesStr[x] <
'0') || (MinutesStr[x] >
'9'))
10704 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in minute increment segment");
10709 RearStartOrRepeatMins = MinutesStr.ToInt();
10710 if(RearStartOrRepeatMins == 0)
10712 TimetableMessage(GiveMessages,
"Repeat minute increment is zero in: '" + OneEntry +
"' - can't have a zero value");
10716 Pos = Remainder.Pos(
';');
10717 AnsiString DigitsStr = Remainder.SubString(1, Pos - 1);
10719 Remainder = Remainder.SubString(Pos + 1, Remainder.Length() - Pos);
10720 if(DigitsStr ==
"")
10722 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - headcode increment segment missing");
10726 for(
int x = 1; x < DigitsStr.Length() + 1; x++)
10728 if((DigitsStr[x] <
'0') || (DigitsStr[x] >
'9'))
10730 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in headcode increment segment");
10735 if(DigitsStr.Length() > 2)
10737 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - maximum number of digits for headcode increment is 2");
10741 FrontStartOrRepeatDigits = DigitsStr.ToInt();
10755 "' - a repeating service with incrementing digits must have digits as its last two headcode characters");
10759 AnsiString NumberStr = Remainder;
10761 if(NumberStr ==
"")
10763 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - number of repeats missing");
10767 if(NumberStr.Length() > 4)
10770 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - repeat value too high, no timetabled event can exceed 95 hours & 59 minutes");
10774 for(
int x = 1; x < NumberStr.Length() + 1; x++)
10776 if((NumberStr[x] <
'0') || (NumberStr[x] >
'9'))
10779 TimetableMessage(GiveMessages,
"Error in repeat: '" + OneEntry +
"' - non-digit character in number of repeats");
10784 NumberOfRepeats = NumberStr.ToInt();
10785 if(NumberOfRepeats == 0)
10787 TimetableMessage(GiveMessages,
"Number of repeats is zero in: '" + OneEntry +
"' - if no repeats are needed the repeat should be omitted");
10943 SecondPassMessage(GiveMessages,
"Error in timetable - there appear to be no train services in the timetable, it must contain at least one");
10967 SecondPassMessage(GiveMessages,
"Error in timetable - the following service has no listed events, there must be at least one: " + TDEntry.
HeadCode);
10981 SecondPassMessage(GiveMessages,
"Error in timetable - service must have a start event and at least one other for: " + TDEntry.
HeadCode);
10997 "Error in timetable - a signaller control service can have no more than one item (a repeat) after the start event, see: " +
11009 "Error in timetable - a signaller control service cannot have any other than a repeat after the start event, see: " + TDEntry.
HeadCode);
11036 SecondPassMessage(GiveMessages,
"Error in timetable - finish events Fns-sh and Frh-sh not permitted immediately after an Snt entry for: " +
11047 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11052 SecondPassMessage(GiveMessages,
"Error in timetable - a start event is present that is not the first event for: " + TDEntry.
HeadCode);
11062 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11067 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat is present that is not the last item for: " + TDEntry.
HeadCode);
11077 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11088 SecondPassMessage(GiveMessages,
"Error in timetable - the last item must be either a finish event or a repeat for: " + TDEntry.
HeadCode);
11098 SecondPassMessage(GiveMessages,
"Error in timetable - the last event before the repeat must be a finish for: " + TDEntry.
HeadCode);
11110 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11117 SecondPassMessage(GiveMessages,
"Error in timetable - a finish event must be either the last or last but one for: " + TDEntry.
HeadCode);
11126 SecondPassMessage(GiveMessages,
"Error in timetable - the only event that can follow a finish event is a repeat for: " +
11146 if((AVEntry0.
Command ==
"Snt") || (AVEntry0.
Command ==
"Snt-sh"))
11148 AnsiString LocationName =
"";
11164 SecondPassMessage(GiveMessages,
"Error in timetable - stopped 'Snt' or 'Snt-sh' followed by an illegal event for: " +
11165 TDEntry.
HeadCode +
". The event isn't valid for a stationary train.");
11174 SecondPassMessage(GiveMessages,
"Error in timetable - 'Snt' or 'Snt-sh' event at stop location but start speed not zero for: " +
11183 if(AVEntry0.
Command ==
"Snt-sh")
11197 SecondPassMessage(GiveMessages,
"Error in timetable - unlocated 'Snt' not followed by 'Fer', 'pas' or an arrival for: " +
11213 SecondPassMessage(GiveMessages,
"Error in timetable - 'Sfs', 'Sns', 'Sns-sh' or 'Sns-fsh' followed by an illegal event for: " +
11214 TDEntry.
HeadCode +
". The event isn't valid for a stationary train.");
11225 bool FoundFlag =
false;
11231 for(
unsigned int y = 1; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11243 SecondPassMessage(GiveMessages,
"Error in timetable - no location departure following an 'Sfs', 'Sns', 'Sns-sh'or 'Sns-fsh' event for: " +
11256 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11265 ": an event should have had a location name associated with it but it could not be found");
11271 for(
unsigned int z = y + 1; z <
TrainDataVector.at(x).ActionVector.size(); z++)
11291 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11301 SecondPassMessage(GiveMessages,
"Error in timetable - only a repeat can follow a finish entry for: " + TDEntry.
HeadCode);
11308 if(AVEntry.
Command ==
"F-nshs")
11313 SecondPassMessage(GiveMessages,
"Error in timetable - F-nshs (shuttle link) must be the last event for: " + TDEntry.
HeadCode);
11341 SecondPassMessage(GiveMessages,
"Error in timetable - a jbo event is followed by an illegal event for: " + TDEntry.
HeadCode +
11342 ". The event isn't valid for a stationary train.");
11352 SecondPassMessage(GiveMessages,
"Error in timetable - a train split can't be the last event for: " + TDEntry.
HeadCode);
11360 SecondPassMessage(GiveMessages,
"Error in timetable - a train split is followed by an illegal event for: " + TDEntry.
HeadCode +
11361 ". The event isn't valid for a stationary train.");
11379 SecondPassMessage(GiveMessages,
"Error in timetable - a 'cdt' is followed by an illegal event for: " + TDEntry.
HeadCode +
11380 ". The event isn't valid for a stationary train.");
11390 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure can't be the last event for: " + TDEntry.
HeadCode);
11398 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure is followed by an illegal event for: " +
11399 TDEntry.
HeadCode +
". The event isn't valid for a moving train.");
11417 SecondPassMessage(GiveMessages,
"Error in timetable - a pass time is followed by an illegal event for: " + TDEntry.
HeadCode +
11418 ". The event isn't valid for a moving train.");
11440 bool LastEntryIsAnArrival =
false;
11447 LastEntryIsAnArrival =
false;
11448 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11455 throw Exception(
"Timetable error, TimeLoc times not as initially set for " + TDEntry.
HeadCode);
11457 if(LastEntryIsAnArrival)
11461 LastEntryIsAnArrival =
false;
11467 LastEntryIsAnArrival =
true;
11474 LastEntryIsAnArrival =
true;
11475 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11482 throw Exception(
"Timetable error, TimeLoc times not as initially set for " + TDEntry.
HeadCode);
11484 if(LastEntryIsAnArrival)
11488 LastEntryIsAnArrival =
false;
11494 LastEntryIsAnArrival =
true;
11504 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11512 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival can't be the last event for: " + TDEntry.
HeadCode);
11520 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival is followed by an illegal event for: " + TDEntry.
HeadCode +
11521 ". The event isn't valid for a stationary train.");
11532 SecondPassMessage(GiveMessages,
"Error in timetable - a timed departure can't be the last event for: " + TDEntry.
HeadCode);
11540 SecondPassMessage(GiveMessages,
"Error in timetable - a timed departure is followed by an illegal event for: " + TDEntry.
HeadCode +
11541 ". The event isn't valid for a moving train.");
11555 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11562 throw Exception(
"Timetable error, TimeLoc entry has EventTime not -1 for " + TDEntry.
HeadCode);
11566 throw Exception(
"Timetable error, TimeLoc entry has neither arrival nor departure time set for " + TDEntry.
HeadCode);
11573 throw Exception(
"Timetable error, TimeTimeLoc entry has EventTime not -1 for " + TDEntry.
HeadCode);
11577 throw Exception(
"Timetable error, TimeTimeLoc entry has either arrival or departure time not set for " + TDEntry.
HeadCode);
11586 throw Exception(
"Timetable error, Cmd or PassTime entry has EventTime not set for " + TDEntry.
HeadCode);
11590 throw Exception(
"Timetable error, Cmd or PassTime entry has either arrival or departure time set for " + TDEntry.
HeadCode);
11597 throw Exception(
"Timetable error, Repeat entry has a time set for " + TDEntry.
HeadCode);
11608 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11619 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure has a later arrival than departure time for: " +
11627 SecondPassMessage(GiveMessages,
"Error in timetable - a timed arrival and departure has too early an arrival time for: " +
11642 SecondPassMessage(GiveMessages,
"Error in timetable - a timed location event has a time that is too early for: " + TDEntry.
HeadCode);
11654 SecondPassMessage(GiveMessages,
"Error in timetable - a timed location event has a time that is too early for: " + TDEntry.
HeadCode);
11666 SecondPassMessage(GiveMessages,
"Error in timetable - a train event has a time that is set too early for: " + TDEntry.
HeadCode +
11667 ", may be before timetable start time");
11678 AnsiString LastLocationName =
"";
11682 bool LastEntryIsAnArrival =
false;
11687 LastEntryIsAnArrival =
false;
11688 LastLocationName =
TrainDataVector.at(x).ActionVector.at(0).LocationName;
11689 if(LastLocationName !=
"")
11691 throw Exception(
"Timetable error, moving Snt entry has LocationName set for " + TDEntry.
HeadCode);
11693 for(
unsigned int y = 1; y <
TrainDataVector.at(x).ActionVector.size();
11704 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
11716 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
11728 ShowMessage(
"Two or more locations are the same without a change of direction between them. Please correct if this is an error.\n\nThis warning will not be shown again.");
11737 LastEntryIsAnArrival =
false;
11741 if(LastEntryIsAnArrival && (AVEntry.
LocationName != LastLocationName))
11744 "Error in timetable - a location event for a timed departure is different from the arrival location for: " + TDEntry.
HeadCode);
11749 else if(!LastEntryIsAnArrival && (AVEntry.
LocationName == LastLocationName))
11752 "Error in timetable - a location event for a timed arrival is the same as the earlier departure location for: " + TDEntry.
HeadCode);
11758 LastEntryIsAnArrival = !LastEntryIsAnArrival;
11764 LastEntryIsAnArrival =
true;
11765 LastLocationName =
TrainDataVector.at(x).ActionVector.at(0).LocationName;
11766 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11776 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
11788 SecondPassMessage(GiveMessages,
"Error in timetable - a location event is inconsistent for: " + TDEntry.
HeadCode +
" && " +
11800 ShowMessage(
"Two or more locations are the same without a change of direction between them. Please correct if this is an error.\n\nThis warning will not be shown again.");
11809 LastEntryIsAnArrival =
false;
11813 if(LastEntryIsAnArrival && (AVEntry.
LocationName != LastLocationName))
11816 "Error in timetable - a location event for a timed departure is different from the arrival location for: " + TDEntry.
HeadCode);
11824 "A location event for a timed arrival is the same as the earlier departure location for: " + TDEntry.
HeadCode +
". Please correct if this is an error.\n\nThis warning will not be shown again.");
11831 LastEntryIsAnArrival = !LastEntryIsAnArrival;
11840 AnsiString LocationNameToBeChecked =
"";
11845 unsigned int y = 0;
11860 LocationNameToBeChecked = TDEntry.
ActionVector.at(y).LocationName;
11861 for(
unsigned int z = y; z < TDEntry.
ActionVector.size(); z++)
11877 for(
unsigned int a = z; a < TDEntry.
ActionVector.size(); a++)
11885 ShowMessage(
"Two or more locations are the same without a change of direction between them. Please correct if this is an error.\n\nThis warning will not be shown again.");
11904 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11909 throw Exception(
"Error, non- 'Snt', 'Fer' or Repeat entry doesn't have a location name set for " + TDEntry.
HeadCode);
11911 AnsiString LocName =
"";
11917 throw Exception(
"Error, 'Snt' entry at a stop location doesn't have a location name set for " + TDEntry.
HeadCode);
11924 throw Exception(
"Error, 'Snt' unlocated entry has a location name set for " + TDEntry.
HeadCode);
11947 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11972 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
11994 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12016 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12035 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12038 if((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh"))
12053 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12058 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has FormatType unset for: " + TDEntry.
HeadCode);
12062 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has SequenceType unset for: " + TDEntry.
HeadCode);
12066 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has LocationType unset for: " + TDEntry.
HeadCode);
12070 throw Exception(
"Error - timetable ActionVector entry no. " + AnsiString(y) +
" has ShuttleLinkType unset for: " + TDEntry.
HeadCode);
12107 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12109 AnsiString LocName =
TrainDataVector.at(x).ActionVector.at(y).LocationName;
12115 SecondPassMessage(GiveMessages,
"Error in timetable - continuation names (" + LocName +
") must not be included, see service " + HC);
12128 int IncMinutes = 0;
12136 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12142 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat time exceeds 95h 59m, see service " + HC);
12148 if((
double)
TrainDataVector.at(x).ActionVector.at(y).ArrivalTime > -1)
12153 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat entry time exceeds 95h 59m, see service " + HC);
12159 if((
double)
TrainDataVector.at(x).ActionVector.at(y).DepartureTime > -1)
12164 SecondPassMessage(GiveMessages,
"Error in timetable - a repeat entry time exceeds 95h 59m, see service " + HC);
12177 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12203 (AVEntry.
Command ==
"Fns-sh") || (AVEntry.
Command ==
"F-nshs"));
12211 if(HeadCode.Length() > 4)
12213 HeadCode = HeadCode.SubString(HeadCode.Length() - 3, 4);
12224 int ForwardCount = 0;
12225 int ReverseCount = 0;
12227 if(MainHeadCode == SecondHeadCode)
12229 SecondPassMessage(GiveMessages,
"Error in timetable - Service " + MainHeadCode +
" has an event that references itself");
12239 if(TDEntry.
HeadCode == MainHeadCode)
12241 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12256 if(ForwardCount == 0)
12259 throw Exception(
"Error, ForwardCount == 0 in CheckForDuplicateCrossReferences after called with found values");
12262 if(ForwardCount > 2)
12265 SecondPassMessage(GiveMessages,
"Error in timetable - found more than two references to " + SecondHeadCode +
" from a train whose headcode is " +
12266 MainHeadCode +
". Check the service cross references from each service, and check whether one or other service is listed twice or more.");
12276 if(TDEntry.
HeadCode == SecondHeadCode)
12278 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12293 if(ReverseCount == 0)
12295 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + SecondHeadCode);
12300 if(ReverseCount > 2)
12303 SecondPassMessage(GiveMessages,
"Error in timetable - found more than two references to " + MainHeadCode +
" from a train whose headcode is " +
12304 SecondHeadCode +
". Check the service cross references from each service, and check whether one or other service is listed twice or more.");
12310 if(ForwardCount != ReverseCount)
12312 SecondPassMessage(GiveMessages,
"Error in timetable - " + MainHeadCode +
" has a different number of references to " + SecondHeadCode +
12313 " than the other way round");
12345 int ForwardCount = 0;
12346 int ReverseCount = 0;
12347 unsigned int ForwardTDVectorNumber, ReverseTDVectorNumber;
12356 if(TDEntry.
HeadCode == MainHeadCode)
12358 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12361 if(!Shuttle && (AVEntry.
Command !=
"Sns-sh") && (AVEntry.
Command !=
"Snt-sh") && (AVEntry.
Command !=
"Fns-sh") && (AVEntry.
Command !=
"Frh-sh"))
12366 ForwardEntryPtr = &AVEntry;
12368 ForwardTDVectorNumber = x;
12371 else if(Shuttle && ((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh") || (AVEntry.
Command ==
"Fns-sh") ||
12372 (AVEntry.
Command ==
"Frh-sh")))
12377 ForwardEntryPtr = &AVEntry;
12379 ForwardTDVectorNumber = x;
12385 if(ForwardCount == 0)
12388 throw Exception(
"Error, ForwardCount == 0 in CheckCrossReferencesAndSetData after called with found values");
12390 if(ForwardCount > 1)
12392 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + OtherHeadCode +
" from a train whose headcode is " +
12403 if(TDEntry.
HeadCode == OtherHeadCode)
12405 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
12408 if(!Shuttle && (AVEntry.
Command !=
"Sns-sh") && (AVEntry.
Command !=
"Snt-sh") && (AVEntry.
Command !=
"Fns-sh") && (AVEntry.
Command !=
"Frh-sh"))
12414 ReverseEntryPtr = &AVEntry;
12415 ReverseTDVectorNumber = x;
12418 else if(Shuttle && ((AVEntry.
Command ==
"Sns-sh") || (AVEntry.
Command ==
"Snt-sh") || (AVEntry.
Command ==
"Fns-sh") || (AVEntry.
Command ==
"Frh-sh")))
12424 ReverseEntryPtr = &AVEntry;
12425 ReverseTDVectorNumber = x;
12432 if(ReverseCount == 0)
12434 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + OtherHeadCode);
12439 if(ReverseCount > 1)
12441 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + MainHeadCode +
" from a train whose headcode is " +
12449 bool ForwardShuttleStart = ((ForwardEntryPtr->Command ==
"Sns-sh") || (ForwardEntryPtr->Command ==
"Snt-sh"));
12450 bool ForwardShuttleFinish = ((ForwardEntryPtr->Command ==
"Fns-sh") || (ForwardEntryPtr->Command ==
"Frh-sh"));
12451 bool ReverseShuttleStart = ((ReverseEntryPtr->
Command ==
"Sns-sh") || (ReverseEntryPtr->
Command ==
"Snt-sh"));
12452 bool ReverseShuttleFinish = ((ReverseEntryPtr->
Command ==
"Fns-sh") || (ReverseEntryPtr->
Command ==
"Frh-sh"));
12456 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + MainHeadCode +
" does not have a repeat");
12464 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + OtherHeadCode +
" does not have a repeat");
12470 if(ForwardEntryPtr->LocationName ==
"")
12472 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + OtherHeadCode +
12473 ". One or other service does not have a location set");
12481 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + OtherHeadCode +
12482 ". One or other service does not have a location set");
12488 if(ForwardEntryPtr->LocationName != ReverseEntryPtr->
LocationName)
12490 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + OtherHeadCode +
12491 " is at a different location to the referencing train " + MainHeadCode);
12500 if(ForwardEntryPtr->EventTime != ReverseEntryPtr->
EventTime)
12502 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + OtherHeadCode +
12503 " has a different event time to the referencing train " + MainHeadCode);
12512 if(ForwardShuttleStart && ReverseShuttleFinish)
12517 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle service " + MainHeadCode +
12518 " first repeat restart time not consistent with finish service " + OtherHeadCode);
12525 if((ReverseEntryPtr->
Command ==
"Sfs") || (ReverseEntryPtr->
Command ==
"Sns"))
12528 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
12530 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Sfs' or 'Sns' event (" + OtherHeadCode +
12531 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
12538 if(ReverseEntryPtr->
Command ==
"Fjo")
12541 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
12543 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Fjo' event (" + OtherHeadCode +
12544 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
12551 if(ReverseEntryPtr->
Command ==
"Fns")
12554 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
12556 SecondPassMessage(GiveMessages,
"Error in timetable - an 'Fns' event (" + OtherHeadCode +
12557 ") appears in the same sequence as the corresponding linked event " + MainHeadCode);
12564 if(ForwardEntryPtr->Command ==
"Sfs")
12566 if((ReverseEntryPtr->
Command !=
"fsp") && (ReverseEntryPtr->
Command !=
"rsp"))
12569 "Error in timetable - unable to find a corresponding split train event for the train that starts from a split whose headcode is " +
12577 if((ForwardEntryPtr->Command ==
"fsp") || (ForwardEntryPtr->Command ==
"rsp"))
12579 if(ReverseEntryPtr->
Command !=
"Sfs")
12581 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sfs' event for the train split whose headcode is " +
12591 SecondPassMessage(GiveMessages,
"Error in timetable - can't find timetabled location '" + ForwardEntryPtr->LocationName +
"' in railway - perhaps there are concourses without platforms?");
12598 SecondPassMessage(GiveMessages,
"Error in timetable - can't find any named location elements at '" + ForwardEntryPtr->LocationName +
"' - perhaps there are concourses without platforms?");
12605 SecondPassMessage(GiveMessages,
"Error in timetable - location too short to split a train at " + ForwardEntryPtr->LocationName);
12610 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
12620 if(ForwardEntryPtr->Command ==
"Sns")
12622 if(ReverseEntryPtr->
Command !=
"Fns")
12624 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Fns' event for the 'Sns' train whose headcode is " +
12625 MainHeadCode +
" and is formed from a service with headcode " + OtherHeadCode);
12632 if(ForwardEntryPtr->Command ==
"Fns")
12634 if(ReverseEntryPtr->
Command !=
"Sns")
12636 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sns' event for the train whose headcode is " + MainHeadCode +
12637 " and forms a new service with headcode " + OtherHeadCode);
12644 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
12653 if(ForwardEntryPtr->Command ==
"jbo")
12655 if(ReverseEntryPtr->
Command !=
"Fjo")
12657 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Fjo' event for the train whose headcode is " + MainHeadCode +
12658 " and is joined by a train with headcode " + OtherHeadCode);
12665 if(ForwardEntryPtr->Command ==
"Fjo")
12667 if(ReverseEntryPtr->
Command !=
"jbo")
12669 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'jbo' event for the train whose headcode is " + MainHeadCode +
12670 " and joins a train with headcode " + OtherHeadCode);
12677 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
12686 if(ForwardShuttleStart)
12689 if(!ReverseShuttleFinish)
12692 SecondPassMessage(GiveMessages,
"Error in timetable - incorrect shuttle link to train whose headcode is " + MainHeadCode +
12693 " from train whose headcode is " + OtherHeadCode +
", has to be Fns-sh, Frh-sh");
12700 if(ReverseShuttleStart)
12703 if(!ForwardShuttleFinish)
12706 SecondPassMessage(GiveMessages,
"Error in timetable - incorrect shuttle link to train whose headcode is " + OtherHeadCode +
12707 " from train whose headcode is " + MainHeadCode +
", has to be Fns-sh, Frh-sh");
12714 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
12727 bool MainRepeat =
false, OtherRepeat =
false;
12737 OtherRepeat =
true;
12740 if((MainRepeat && !OtherRepeat) || (!MainRepeat && OtherRepeat))
12742 SecondPassMessage(GiveMessages,
"Error in timetable - only one repeat is provided for the train whose headcode is " + MainHeadCode +
12743 " and the associated train with headcode " + OtherHeadCode);
12748 if(MainRepeat && OtherRepeat)
12754 SecondPassMessage(GiveMessages,
"Error in timetable - repeat items don't correspond for the train whose headcode is " + MainHeadCode +
12755 " and the associated train with headcode " + OtherHeadCode);
12777 while(Input[1] ==
' ')
12779 if(Input.Length() > 1)
12781 Input = Input.SubString(2, Input.Length() - 1);
12795 while(Input[Input.Length()] ==
' ')
12797 if(Input.Length() > 1)
12799 Input = Input.SubString(1, Input.Length() - 1);
12809 AnsiString Output =
"";
12810 bool DelimiterFound =
false;
12812 for(
int x = 1; x < Input.Length() + 1; x++)
12816 if(Input[x] ==
' ')
12819 if((Input[x] !=
',') && (Input[x] !=
';'))
12821 DelimiterFound =
false;
12822 Output = Output + Input[x];
12826 DelimiterFound =
true;
12827 Output = Output + Input[x];
12839 DelimiterFound =
false;
12840 for(
int x = Input.Length(); x > 0; x--)
12844 if(Input[x] ==
' ')
12847 if((Input[x] !=
',') && (Input[x] !=
';'))
12849 DelimiterFound =
false;
12850 Output = AnsiString(Input[x]) + Output;
12854 DelimiterFound =
true;
12855 Output = AnsiString(Input[x]) + Output;
12875 if((AVEntry0.
Command !=
"Snt") && (AVEntry0.
Command !=
"Snt-sh"))
12877 throw Exception(
"Error, first entry not 'Snt' or 'Snt-sh' in IsSNTEntryLocated");
12888 LocationName = LocRear;
12890 LocationName = LocFront;
12891 if(LocationName ==
"")
12917 AnsiString TimeLocLocationName;
12918 bool FoundFlag =
false;
12920 for(
unsigned int y = 0; y < TDEntry.
ActionVector.size(); y++)
12935 if(TimeLocLocationName == LocationName)
12952 int RearPosition = 0, FrontPosition = 0, RearExitPos = 0;
12955 if(RearPosition < 0)
12962 if(FrontPosition < 0)
12973 for(
int x = 0; x < 4; x++)
12975 if(RearTrackElement.
Conn[x] == FrontPosition)
12990 TimetableMessage(GiveMessages,
"Front of train attempting to start on a continuation at: " + FrontElementStr);
12998 TimetableMessage(GiveMessages,
"Train attempting to start on a level crossing at: " + FrontElementStr);
13004 TimetableMessage(GiveMessages,
"Train attempting to start on a level crossing at: " + RearElementStr);
13010 if((RearType ==
Points) && (RearExitPos == 3))
13012 TimetableMessage(GiveMessages,
"Front of train attempting to start on element connected to diverging points at: " + RearElementStr);
13019 TimetableMessage(GiveMessages,
"Rear of train attempting to start on element connected to diverging points at: " + FrontElementStr);
13034 AnsiString(RearExitPos));
13041 int FrontPosition = RearTrackElement.
Conn[RearExitPos];
13043 int FrontEntryPos = RearTrackElement.
ConnLinkPos[RearExitPos];
13046 AnsiString RearName, FrontName;
13055 FrontName = FrontTrackElement.
ElementID;
13058 int LockedVectorNumber;
13193 "," + AnsiString(IncDigits));
13196 throw Exception(
"Error, last 2 characters not both digits and IncDigits > 0 in GetRepeatHeadCode");
13201 return BaseHeadCode;
13203 int BaseDigits = BaseHeadCode.SubString(3, 2).ToInt();
13204 int NextRepeatDigits = BaseDigits + (IncDigits * RepeatNumber);
13206 while(NextRepeatDigits >= 100)
13208 NextRepeatDigits -= 100;
13210 AnsiString NextRepeatDigitsStr = AnsiString(NextRepeatDigits);
13212 if(NextRepeatDigitsStr.Length() < 2)
13213 NextRepeatDigitsStr = AnsiString(
'0') + NextRepeatDigitsStr;
13214 AnsiString NextRepeatHeadCode = BaseHeadCode.SubString(1, 2) + NextRepeatDigitsStr;
13217 return NextRepeatHeadCode;
13225 AnsiString(RepeatNumber) +
"," + AnsiString(IncMinutes));
13226 TDateTime NextRepeatTime = BasicTime + TDateTime(((
double)(RepeatNumber * IncMinutes)) / 1440.0);
13229 return NextRepeatTime;
13238 AnsiString(
double(ReverseEventTime)) +
"," + AnsiString(RepeatMinutes));
13239 int ForwardSecs = int(
double(ForwardEventTime) * 86400);
13240 int ReverseSecs = int(
double(ReverseEventTime) * 86400);
13241 int RepeatSecs = RepeatMinutes * 60;
13243 if((ForwardSecs > (ReverseSecs - RepeatSecs + 10)) || (ForwardSecs < (ReverseSecs - RepeatSecs - 10)))
13261 NonRepeatingHeadCode);
13262 int ForwardCount = 0;
13263 int ReverseCount = 0;
13264 unsigned int ForwardTDVectorNumber, ReverseTDVectorNumber;
13274 if(TDEntry.
HeadCode == MainHeadCode)
13276 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13282 ForwardEntryPtr = &AVEntry;
13284 ForwardTDVectorNumber = x;
13289 if(ForwardCount == 0)
13292 throw Exception(
"Error, ForwardCount == 0 in CheckNonRepeatingShuttleLinksAndSetData after called with found values");
13294 if(ForwardCount > 1)
13296 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + NonRepeatingHeadCode +
" from a train whose headcode is " +
13307 if(TDEntry.
HeadCode == NonRepeatingHeadCode)
13309 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13316 ReverseEntryPtr = &AVEntry;
13317 ReverseTDVectorNumber = x;
13323 if(ReverseCount == 0)
13325 SecondPassMessage(GiveMessages,
"Error in timetable - cross reference missing in either " + MainHeadCode +
" or " + NonRepeatingHeadCode);
13330 if(ReverseCount > 1)
13332 SecondPassMessage(GiveMessages,
"Error in timetable - found more than one reference to " + MainHeadCode +
" from a train whose headcode is " +
13333 NonRepeatingHeadCode);
13339 if(((ForwardEntryPtr->Command ==
"F-nshs") || (ForwardEntryPtr->Command ==
"Sns-fsh")) && (MainTrainDataPtr->
ActionVector.back().FormatType ==
Repeat))
13341 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle connecting train " + MainHeadCode +
" shouldn't have a repeat");
13347 if((ForwardEntryPtr->Command !=
"F-nshs") && (ForwardEntryPtr->Command !=
"Sns-fsh") && (MainTrainDataPtr->
ActionVector.back().FormatType !=
Repeat))
13349 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle train " + MainHeadCode +
" does not have a repeat item");
13355 if(ForwardEntryPtr->LocationName ==
"")
13357 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + NonRepeatingHeadCode +
13358 ". One or other service does not have a location set");
13366 SecondPassMessage(GiveMessages,
"Error in timetable - location error in cross referenced trains " + MainHeadCode +
" and " + NonRepeatingHeadCode +
13367 ". One or other service does not have a location set");
13373 if(ForwardEntryPtr->LocationName != ReverseEntryPtr->
LocationName)
13375 SecondPassMessage(GiveMessages,
"Error in timetable - cross referenced train " + NonRepeatingHeadCode +
13376 " is at a different location to the referencing train " + MainHeadCode);
13382 if(ForwardEntryPtr->Command ==
"F-nshs")
13385 if(ForwardEntryPtr->EventTime != ReverseEntryPtr->
EventTime)
13387 SecondPassMessage(GiveMessages,
"Error in timetable - shuttle in-link service " + MainHeadCode +
13388 " finish time not consistent with start time of shuttle service " + NonRepeatingHeadCode);
13395 if(ForwardEntryPtr->Command ==
"Fns-sh")
13399 MainTrainDataPtr->
ActionVector.back().RearStartOrRepeatMins, MainTrainDataPtr->
ActionVector.back().NumberOfRepeats))
13401 SecondPassMessage(GiveMessages,
"Error in timetable - service " + NonRepeatingHeadCode +
", which links out from shuttle service " + MainHeadCode +
13402 ", has the wrong start time. It should correspond to the finish time of the last shuttle.");
13409 if((ForwardEntryPtr->Command ==
"F-nshs") || (ForwardEntryPtr->Command ==
"Sns-fsh"))
13412 if(ReverseTDVectorNumber == ForwardTDVectorNumber)
13414 SecondPassMessage(GiveMessages,
"Error in timetable - the non repeating link service " + NonRepeatingHeadCode +
13415 " appears in the same sequence as the corresponding shuttle service " + MainHeadCode);
13433 if(ForwardEntryPtr->Command ==
"Sns-sh")
13435 if(ReverseEntryPtr->
Command !=
"F-nshs")
13437 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'F-nshs' event for the 'Sns-sh' train whose headcode is " +
13438 MainHeadCode +
" and is a new shuttle service formed from the service with headcode " + NonRepeatingHeadCode);
13445 if(ForwardEntryPtr->Command ==
"F-nshs")
13447 if(ReverseEntryPtr->
Command !=
"Sns-sh")
13449 SecondPassMessage(GiveMessages,
"Error in timetable - unable to find a corresponding 'Sns-sh' event for the 'F-nshs' train whose headcode is " +
13450 MainHeadCode +
" and forms a new shuttle service with headcode " + NonRepeatingHeadCode);
13457 ForwardEntryPtr->LinkedTrainEntryPtr = OtherTrainDataPtr;
13467 if(ForwardEntryPtr->Command ==
"Sns-fsh")
13469 if(ReverseEntryPtr->
Command !=
"Fns-sh")
13472 "Error in timetable - unable to find a corresponding 'Fns-sh' event for the 'Sns-fsh' non-shuttle service whose headcode is " + MainHeadCode +
13473 " formed from a shuttle service with headcode " + NonRepeatingHeadCode);
13480 if(ForwardEntryPtr->Command ==
"Fns-sh")
13482 if(ReverseEntryPtr->
Command !=
"Sns-fsh")
13485 "Error in timetable - unable to find a corresponding 'Sns-fsh' event for the 'Fns-sh' shuttle service whose headcode is " + MainHeadCode +
13486 " and forms a new non-shuttle service with headcode " + NonRepeatingHeadCode);
13493 ForwardEntryPtr->NonRepeatingShuttleLinkEntryPtr = OtherTrainDataPtr;
13516 +
"," + AnsiString(
double(ReverseEventTime)) +
"," + AnsiString(RepeatMinutes) +
"," + AnsiString(RepeatNumber));
13517 int ForwardSecs = int(
double(ForwardEventTime) * 86400);
13518 int ReverseSecs = int(
double(ReverseEventTime) * 86400);
13519 int RepeatSecs = RepeatMinutes * RepeatNumber * 60;
13521 if((ReverseSecs > (ForwardSecs + RepeatSecs + 10)) || (ReverseSecs < (ForwardSecs + RepeatSecs - 10)))
13545 throw Exception(
"Error - last entry in " + TDEntryPtr->
HeadCode +
" service is not a repeat - should have already found this error");
13548 AnsiString OriginalHeadCode = TDEntryPtr->
HeadCode;
13549 AnsiString LastActionCommand = (TDEntryPtr->
ActionVector.end() - 2)->Command;
13551 if((LastActionCommand !=
"Fns") && (LastActionCommand !=
"Fns-sh") && (LastActionCommand !=
"Frh-sh"))
13553 SecondPassMessage(GiveMessages,
"Error in timetable - last event in shuttle service " + TDEntryPtr->
HeadCode +
" is not 'Fns', 'Fns-sh' or 'Frh-sh'");
13558 while(LastActionCommand ==
"Fns")
13560 TDEntryPtr = (TDEntryPtr->
ActionVector.end() - 2)->LinkedTrainEntryPtr;
13561 LastActionCommand = (TDEntryPtr->
ActionVector.end() - 2)->Command;
13562 if((LastActionCommand !=
"Fns") && (LastActionCommand !=
"Fns-sh") && (LastActionCommand !=
"Frh-sh"))
13565 "Error in timetable - last event in a continuation shuttle service (i.e links back to a shuttle) whose headcode is " + TDEntryPtr->
HeadCode +
13566 " is not 'Fns', 'Fns-sh' or 'Frh-sh'");
13573 if((TDEntryPtr->
ActionVector.end() - 2)->LinkedTrainEntryPtr != ShuttleStartAddress)
13576 " is a shuttle finish, but it doesn't link back to the start of the original shuttle starting service " + OriginalHeadCode +
13577 ". The linking of two or more shuttles is not permitted.");
13595 ShowMessage(Message);
13609 ShowMessage(Message);
13647 AnsiString(ActionEventType) +
"," + LocationID);
13648 AnsiString BaseLog =
"", Prefix =
"", ErrorLog =
"", WarningStr =
"";
13650 Prefix =
" ERROR: ";
13653 Prefix =
" HELD: ";
13654 ErrorLog =
" can't enter railway, train obstructing entry position ";
13655 WarningStr =
" can't enter railway, train obstructing entry position ";
13660 Prefix =
" HELD: ";
13661 ErrorLog =
" can't be created, train obstructing ";
13662 WarningStr =
" can't be created, train obstructing ";
13667 Prefix =
" HELD: ";
13668 ErrorLog =
" can't be created on a locked route at ";
13669 WarningStr =
" can't be created on a locked route at ";
13674 Prefix =
" HELD: ";
13675 ErrorLog =
" can't enter on a locked route at ";
13676 WarningStr =
" can't enter on a locked route at ";
13681 Prefix =
" HELD: ";
13682 ErrorLog =
" can't be created, diverging points at ";
13683 WarningStr =
" can't be created, diverging points at ";
13688 ErrorLog =
" left railway unexpectedly at ";
13693 ErrorLog =
" left railway at an incorrect exit at ";
13698 ErrorLog =
" failed to split - location too short at ";
13699 WarningStr =
" failed to split, location too short at ";
13704 Prefix =
" HELD: ";
13705 ErrorLog =
" unable to split - other train obstructing at ";
13706 WarningStr =
" unable to split - other train obstructing at ";
13710 ErrorLog =
" stopped at buffers unexpectedly at position ";
13713 ErrorLog =
" failed to stop at ";
13718 ErrorLog =
" failed to split at ";
13723 ErrorLog =
" failed to be joined by other train at ";
13728 ErrorLog =
" failed to join other train at ";
13733 ErrorLog =
" failed to terminate at ";
13738 ErrorLog =
" failed to form new service at ";
13743 ErrorLog =
" failed to exit railway ";
13748 ErrorLog =
" failed to change direction at ";
13753 ErrorLog =
" failed to pass ";
13757 ErrorLog =
" facing buffers and unable to start at ";
13760 ErrorLog =
" DERAILED at position ";
13761 Prefix =
" DERAILMENT: ";
13766 ErrorLog =
" CRASHED INTO BUFFERS at ";
13767 Prefix =
" CRASH: ";
13772 ErrorLog =
" CRASHED INTO ROAD TRAFFIC AT A LEVEL CROSSING at ";
13773 Prefix =
" CRASH: ";
13778 ErrorLog =
" CRASHED INTO " + OtherHeadCode +
" at position ";
13779 Prefix =
" CRASH: ";
13783 else if(ActionEventType ==
FailSPAD)
13785 ErrorLog =
" PASSED SIGNAL AT DANGER at position ";
13786 Prefix =
" SPAD: ";
13791 ErrorLog =
"Signals reset ahead of train, route cancelled at position ";
13792 Prefix =
" SPAD RISK: ";
13797 ErrorLog =
" forced a route cancellation by occupying it incorrectly at ";
13801 Prefix =
" WARNING: ";
13802 ErrorLog =
" waiting to join " + OtherHeadCode +
" at ";
13803 WarningStr =
" waiting to join " + OtherHeadCode +
" at ";
13808 Prefix =
" WARNING: ";
13809 ErrorLog =
" waiting to be joined by " + OtherHeadCode +
" at ";
13810 WarningStr =
" waiting to be joined by " + OtherHeadCode +
" at ";
13849 std::ofstream OutFile(
"TrainData.csv");
13853 ShowMessage(
"Output file TrainData.csv failed to open");
13860 OutFile <<
"HeadCode" <<
',' <<
"Description" <<
',' <<
"StartSpeed" <<
',' <<
"MaxRunningSpeed" <<
',' <<
"NumberOfTrains" <<
'\n' <<
'\n';
13865 OutFile <<
',' <<
"FormatType" <<
',' <<
"EventTime" <<
',' <<
"ArrivalTime" <<
',' <<
"DepartureTime" <<
',' <<
"LocationName" <<
',' <<
"Command" <<
13866 ',' <<
"OtherHeadCode" <<
',' <<
"LinkedTrainEntryPtr" <<
',' <<
"RearStartOrRepeatMins" <<
',' <<
"FrontStartOrRepeatDigits" <<
',' <<
13867 "RepeatNumber" <<
'\n' <<
'\n';
13868 for(
unsigned int y = 0; y <
TrainDataVector.at(x).ActionVector.size(); y++)
13871 AnsiString TimetableEntryTypeStr;
13877 TimetableEntryTypeStr =
"NoFormat";
13883 TimetableEntryTypeStr =
"TimeLoc";
13889 TimetableEntryTypeStr =
"TimeTimeLoc";
13895 TimetableEntryTypeStr =
"TimeCmd";
13901 TimetableEntryTypeStr =
"StartNew";
13907 TimetableEntryTypeStr =
"TimeCmdHeadCode";
13913 TimetableEntryTypeStr =
"FinRemHere";
13919 TimetableEntryTypeStr =
"FNSShuttle";
13925 TimetableEntryTypeStr =
"SNTShuttle";
13931 TimetableEntryTypeStr =
"SNSShuttle";
13937 TimetableEntryTypeStr =
"SNSNonRepeatFromShuttle";
13943 TimetableEntryTypeStr =
"FSHNewService";
13949 TimetableEntryTypeStr =
"Repeat";
13955 TimetableEntryTypeStr =
"Default";
13965 OutFile <<
',' <<
',' <<
"Mass" <<
',' <<
"MaxBrakeRate" <<
',' <<
"PowerAtRail" <<
',' <<
"TrainID" <<
',' <<
"RunningEntry" <<
'\n' <<
'\n';
13966 for(
unsigned int y = 0; y <
TrainDataVector.at(x).TrainOperatingDataVector.size(); y++)
13969 AnsiString RunningEntryStr;
13975 RunningEntryStr =
"NotStarted";
13981 RunningEntryStr =
"Running";
13987 RunningEntryStr =
"Exited";
13990 OutFile <<
',' <<
',' << TOD.
TrainID <<
',' << RunningEntryStr.c_str() <<
',' <<
'\n';
14007 ShowMessage(Message);
14008 BaseTime = TDateTime::CurrentDateTime();
14022 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
14035 TTrain *NewTrain =
new TTrain(1, 0, 0,
"", 0, 1, 0, 0, 0, (
TTrainMode)0, 0, 0, 0, 0, 0);
14038 for(
int x = 0; x < NumberOfTrains; x++)
14040 *NewTrain =
TTrain(2, 0, 0,
"", 0, 1, 0, 0, 0, (
TTrainMode)0, 0, 0, 0, 0, 0);
14060 int NumberOfTrains;
14067 for(
int x = 0; x < NumberOfTrains; x++)
14104 for(
int x = 0; x < LockedRouteVectorSize; x++)
14111 LockedRouteObject.
LockStartTime = TDateTime(LockStartTimeDouble);
14122 int LockedRouteVectorSize;
14129 for(
int x = 0; x < LockedRouteVectorSize; x++)
14187 for(
int x = 0; x < ContinuationAutoSigVectorSize; x++)
14195 ContinuationAutoSigObject.
PassoutTime = TDateTime(PassoutTimeDouble);
14206 int ContinuationAutoSigVectorSize;
14213 for(
int x = 0; x < ContinuationAutoSigVectorSize; x++)
14283 if(AVFirstEntry.
Command ==
"Snt")
14307 CTEMMP.second = CTEEntry;
14314 throw Exception(
"Error, Last ActionVectorEntry not a repeat in BuildContinuationTrainExpectationMultiMap");
14322 CTEMMP.second = CTEEntry;
14343 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
14360 if((VecPos < 0) || (VecPos >= (
int)
TrainVector.size()))
14362 throw Exception(
"Out of Range Error, vector size: " + AnsiString(
TrainVector.size()) +
", VecPos: " + AnsiString(VecPos) +
" in TrainVectorAt");
14373 AnsiString RetStr =
"", PartStr =
"";
14488 AnsiString TTFileName = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
14492 TTFileName = CurDir +
"\\Formatted timetables\\Timetable " + TTFileName +
"; " + RailwayTitle +
"; " + TimetableTitle +
".csv";
14494 AnsiString ShortTTName =
"";
14496 for(
int x = TTFileName.Length(); x > 0; x--)
14498 if(TTFileName[x] ==
'\\')
14500 ShortTTName = TTFileName.SubString(x + 1, TTFileName.Length() - x - 4);
14505 ShowMessage(
"Creates two timetables named " + ShortTTName +
14506 " in the 'Formatted timetables' folder, one in service order in '.csv' format, and one in chronological order in '.txt' format");
14508 Screen->Cursor = TCursor(-11);
14510 AnsiString FormatNoDPStr =
"#######0";
14511 AnsiString TableTitle =
"", TimetableTimeStr =
"", MassStr =
"", PowerStr =
"", BrakeStr =
"", MaxSpeedStr =
"", FirstHeadCode =
"", Header =
"";
14514 TableTitle =
"Railway: " + RailwayTitle +
"; Timetable: " + TimetableTitle +
"; Start time: " + TimetableTimeStr;
14521 MassStr =
"", PowerStr =
"", BrakeStr =
"", MaxSpeedStr =
"";
14523 if(TrainDataEntry.
Mass > 0)
14524 MassStr =
"; Mass " + AnsiString::FormatFloat(FormatNoDPStr, ((
double)TrainDataEntry.
Mass) / 1000) +
"Te; ";
14526 PowerStr =
"Power " + AnsiString::FormatFloat(FormatNoDPStr, TrainDataEntry.
PowerAtRail / 1000 / 0.8) +
"kW; ";
14528 BrakeStr =
"Brake force " + AnsiString::FormatFloat(FormatNoDPStr, (TrainDataEntry.
MaxBrakeRate * TrainDataEntry.
Mass / 9810)) +
"Te; ";
14530 MaxSpeedStr =
"Maximum speed " + AnsiString::FormatFloat(FormatNoDPStr, TrainDataEntry.
MaxRunningSpeed) +
" km/h";
14531 FirstHeadCode = TrainDataEntry.
HeadCode;
14532 int IncDigits = 0, IncMinutes = 0;
14534 if(!ActionVector.empty())
14536 if(ActionVector.at(ActionVector.size() - 1).FormatType ==
Repeat)
14538 IncDigits = ActionVector.at(ActionVector.size() - 1).FrontStartOrRepeatDigits;
14539 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
14548 if((TrainDataEntry.
Description !=
"") && (MassStr !=
""))
14549 OneTTLine.
Header = TrainDataEntry.
Description + MassStr + PowerStr + BrakeStr + MaxSpeedStr;
14554 for(
unsigned int z = 0; z < ActionVector.size(); z++)
14559 AnsiString PartStr =
"", TimeStr =
"";
14576 PartStr =
"Enters at " + ActionVectorEntry.
LocationName;
14580 PartStr =
"Created at " + ActionVectorEntry.
LocationName;
14590 PartStr =
"Enters at " + LocName;
14603 PartStr =
"Created at " + LocName;
14617 PartStr =
"Enters at " + ActionVectorEntry.
LocationName;
14622 PartStr =
"Repeat shuttle service at " + ActionVectorEntry.
LocationName +
" from ";
14627 else if(ActionVectorEntry.
Command ==
"Sfs")
14629 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" split from";
14633 else if(ActionVectorEntry.
Command ==
"Sns")
14635 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
14643 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
14649 PartStr =
"Repeat shuttle service at " + ActionVectorEntry.
LocationName +
" from ";
14656 PartStr =
"New service at " + ActionVectorEntry.
LocationName +
" from";
14659 AnsiString FirstHeadCode = TDE->
HeadCode;
14663 TimeStr =
GetRepeatHeadCode(36, FirstHeadCode, LastRepeatNumber, IncrementalDigits) +
" at " +
14675 PartStr =
"Arrives at " + ActionVectorEntry.
LocationName;
14677 OneTTEntry.
Action = PartStr;
14678 OneTTEntry.
Time = TimeStr;
14680 PartStr =
"Departs from " + ActionVectorEntry.
LocationName;
14685 PartStr =
"Arrives & departs " + ActionVectorEntry.
LocationName;
14691 PartStr =
"Arrives at " + ActionVectorEntry.
LocationName;
14696 PartStr =
"Departs from " + ActionVectorEntry.
LocationName;
14704 else if(ActionVectorEntry.
Command ==
"jbo")
14706 PartStr =
"Joined at " + ActionVectorEntry.
LocationName +
" by";
14710 else if(ActionVectorEntry.
Command ==
"fsp")
14712 PartStr =
"Splits from front at " + ActionVectorEntry.
LocationName +
" to form";
14716 else if(ActionVectorEntry.
Command ==
"rsp")
14718 PartStr =
"Splits from rear at " + ActionVectorEntry.
LocationName +
" to form";
14722 else if(ActionVectorEntry.
Command ==
"cdt")
14724 PartStr =
"Changes direction at " + ActionVectorEntry.
LocationName;
14730 if(ActionVectorEntry.
Command ==
"Fns")
14732 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
14736 else if(ActionVectorEntry.
Command ==
"F-nshs")
14738 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
14744 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service ";
14751 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
14757 PartStr =
"At " + ActionVectorEntry.
LocationName +
" forms new service";
14764 PartStr =
"Terminates shuttle service at " + ActionVectorEntry.
LocationName;
14769 else if(ActionVectorEntry.
Command ==
"Frh")
14771 PartStr =
"Terminates at " + ActionVectorEntry.
LocationName;
14776 if(ActionVector.at(z - 1).EventTime != TDateTime(-1))
14780 else if(ActionVector.at(z - 1).ArrivalTime != TDateTime(-1))
14788 else if(ActionVectorEntry.
Command ==
"Fer")
14793 else if(ActionVectorEntry.
Command ==
"Fjo")
14795 PartStr =
"At " + ActionVectorEntry.
LocationName +
" joins";
14802 OneTTEntry.
Action = PartStr;
14803 OneTTEntry.
Time = TimeStr;
14810 AllTTTrains->push_back(OneTTLine);
14814 std::ofstream TTFile(TTFileName.c_str());
14818 StopTTClockMessage(64,
"Formatted timetable file failed to open - can't be created");
14819 delete AllTTTrains;
14855 TTFile << TableTitle.c_str() <<
'\n' <<
'\n';
14856 for(
unsigned int x = 0; x < AllTTTrains->size(); x++)
14858 TTFile << AllTTTrains->at(x).Header.c_str();
14861 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
14863 if(y < (AllTTTrains->at(x).NumberOfTrains - 1))
14865 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode.c_str() <<
',';
14869 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode.c_str();
14872 TTFile <<
'\n' <<
'\n';
14874 for(
unsigned int z = 0; z < AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(0).OneFormattedTrainVector.size(); z++)
14876 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(0).OneFormattedTrainVector.at(z).Action.c_str() <<
',';
14877 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
14879 if(y < (AllTTTrains->at(x).NumberOfTrains - 1))
14881 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time.c_str() <<
',';
14885 TTFile << AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time.c_str();
14890 TTFile <<
'\n' <<
'\n';
14895 AnsiString TTFileName2 = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
14897 TTFileName2 = CurDir +
"\\Formatted timetables\\Timetable " + TTFileName2 +
"; " + RailwayTitle +
"; " + TimetableTitle +
".txt";
14899 std::ofstream TTFile2(TTFileName2.c_str());
14903 StopTTClockMessage(67,
"Chronological timetable file failed to open - can't be created");
14904 delete AllTTTrains;
14909 typedef std::multimap<AnsiString, AnsiString>TAnsiMultiMap;
14910 std::multimap<AnsiString, AnsiString>::iterator AMMIT;
14911 std::pair<AnsiString, AnsiString>AnsiMultiMapEntry;
14913 TAnsiMultiMap *TAMM =
new TAnsiMultiMap;
14918 TTFile2 << TableTitle.c_str() <<
'\n' <<
'\n';
14919 for(
unsigned int x = 0; x < AllTTTrains->size(); x++)
14921 for(
int y = 0; y < AllTTTrains->at(x).NumberOfTrains; y++)
14923 for(
unsigned int z = 0; z < AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.size(); z++)
14925 bool GiveMessagesFalse =
false;
14926 AnsiString TimeString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Time;
14927 AnsiString HeadCodeString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).HeadCode;
14928 AnsiString ActionString = AllTTTrains->at(x).OneCompleteFormattedTrainVector.at(y).OneFormattedTrainVector.at(z).Action;
14932 AnsiString OtherHeadCode = TimeString.SubString(1, 4);
14933 TimeString = TimeString.SubString(9, 5);
14934 ActionString +=
" " + OtherHeadCode;
14936 if(TimeString.SubString(1, 7) ==
"End at ")
14939 TimeString = TimeString.SubString(8, 5);
14941 AnsiString OneLine = TimeString +
' ' + HeadCodeString +
' ' + ActionString +
'\n';
14942 AnsiMultiMapEntry.first = TimeString;
14943 AnsiMultiMapEntry.second = OneLine;
14944 TAMM->insert(AnsiMultiMapEntry);
14949 for(AMMIT = TAMM->begin(); AMMIT != TAMM->end(); AMMIT++)
14951 TTFile2 << (AMMIT->second).c_str();
14953 delete AllTTTrains;
14962 bool AtLocChecked,
int ArrRange,
int DepRange)
14966 bool AnalysisError =
false;
14990 TTrainDataVector::iterator TDVIt, TDVCopyIt;
14992 int IteratorNumber = 0;
14993 AnsiString AnsiSuffix =
"";
14998 for(TDVCopyIt = TrainDataVectorCopy.begin() + IteratorNumber; TDVCopyIt != TrainDataVectorCopy.end(); TDVCopyIt++)
15000 if(TDVCopyIt->ServiceReference == TDVIt->ServiceReference)
15003 AnsiSuffix = AnsiString(Suffix);
15004 TDVCopyIt->ServiceReference = TDVIt->ServiceReference +
"/" + AnsiSuffix;
15011 std::pair<AnsiString, TServiceCallingLocsList> AllServiceCallingLocsEntry;
15012 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
15017 ServiceCallingLocsList.clear();
15018 if(ActionVector.empty())
15022 if(ActionVector.at(0).SignallerControl)
15026 for(
unsigned int z = 0; z < ActionVector.size(); z++)
15044 int HLoc = TE.
HLoc;
15045 int VLoc = TE.
VLoc;
15046 AnsiString HString;
15047 AnsiString VString;
15050 HString =
'N' + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
15054 HString = AnsiString(HLoc);
15058 VString =
'N' + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
15062 VString = AnsiString(VLoc);
15064 ServiceCallingLocsList.push_back(HString +
'-' + VString);
15087 else if(AVE.
Command ==
"cdt")
15089 if(ActionVector.at(z-1).SequenceType ==
Start)
15093 else if(ActionVector.at(z+1).SequenceType ==
Finish)
15100 ServiceCallingLocsList.push_back(
"%%%" + TimeString);
15109 ServiceCallingLocsList.push_back(LName);
15113 int HLoc = TE.
HLoc;
15114 int VLoc = TE.
VLoc;
15115 AnsiString HString;
15116 AnsiString VString;
15119 HString =
'N' + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
15123 HString = AnsiString(HLoc);
15127 VString =
'N' + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
15131 VString = AnsiString(VLoc);
15133 ServiceCallingLocsList.push_back(HString +
'-' + VString);
15137 AllServiceCallingLocsEntry.second = ServiceCallingLocsList;
15171 ShowMessage(
"Unable to create a program-readable timetable - please check the timetable file validity");
15177 bool NumPlatsAtThisLocCalculated =
false, ArrivalsPrinted =
false, DeparturesPrinted =
false, AtLocsPrinted =
false;
15178 AnsiString PreviousService =
"", PreviousServiceAndRepeatNumTotalOutput =
"", BasicTime =
"", MinuteString =
"", LastAnsiTime =
"";
15179 int NumTrains = 0, NumPlats = 0, LastFrhCount = 0, FrhCount = 0, NumTrainsAtLoc = 0;
15183 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
15188 TDateTime LastTDTime;
15189 int IncMinutes = 0;
15191 if(ActionVector.empty())
15195 if(ActionVector.at(0).SignallerControl)
15199 if(AVLast->FormatType ==
Repeat)
15201 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
15209 if(AVLast->ArrivalTime != TDateTime(-1))
15211 LastTDTime = AVLast->ArrivalTime;
15213 else if(AVLast->EventTime != TDateTime(-1))
15215 LastTDTime = AVLast->EventTime;
15264 for(
unsigned int x = 0; x < TrainDataVectorCopy.size(); x++)
15269 int IncMinutes = 0;
15271 if(ActionVector.empty())
15275 if(ActionVector.at(0).SignallerControl)
15279 if(ActionVector.at(ActionVector.size() - 1).FormatType ==
Repeat)
15281 IncMinutes = ActionVector.at(ActionVector.size() - 1).RearStartOrRepeatMins;
15284 for(
int y = 0; y < NumTrains; y++)
15298 for(
unsigned int z = 0; z < ActionVector.size(); z++)
15313 LocServiceTimesVector.push_back(TLSTEntry);
15316 AnsiString IncTime =
"", FoundStopTime =
"";
15317 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
15319 if(ActionVector.at(a).FormatType ==
TimeLoc)
15324 if(ActionVector.at(a).SequenceType ==
Finish)
15330 if(FoundStopTime ==
"")
15332 throw Exception(
"Failure to determine FoundStopTime for located Snt");
15334 int WhileCount = 0;
15343 if(IncTime >= FoundStopTime)
15347 LocServiceTimesVector.push_back(TLSTEntry);
15348 if(WhileCount > 2000)
15350 throw Exception(
"While loop failed to break in 2000 loops for located Snt");
15363 int HLoc = TE.
HLoc;
15364 int VLoc = TE.
VLoc;
15365 AnsiString HString;
15366 AnsiString VString;
15369 HString =
'N' + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
15373 HString = AnsiString(HLoc);
15377 VString =
'N' + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
15381 VString = AnsiString(VLoc);
15383 TLSTEntry.
Location = HString +
'-' + VString;
15387 LocServiceTimesVector.push_back(TLSTEntry);
15395 LocServiceTimesVector.push_back(TLSTEntry);
15397 AnsiString IncTime =
"", FoundStopTime =
"";
15398 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
15400 if(ActionVector.at(a).FormatType ==
TimeLoc)
15405 if(ActionVector.at(a).SequenceType ==
Finish)
15411 if(FoundStopTime ==
"")
15413 throw Exception(
"Failure to determine FoundStopTime for SequenceType == Start");
15415 int WhileCount = 0;
15424 if(IncTime >= FoundStopTime)
15428 LocServiceTimesVector.push_back(TLSTEntry);
15429 if(WhileCount > 2000)
15431 throw Exception(
"While loop failed to break in 2000 loops for SequenceType == Start");
15441 bool SkipAddingMinutes =
false;
15444 LocServiceTimesVector.push_back(TLSTEntry);
15446 AnsiString IncTime =
"", FoundStopTime =
"";
15447 for(
unsigned int a = z + 1; a < ActionVector.size(); a++)
15449 if(ActionVector.at(a).FormatType ==
TimeLoc)
15454 if(ActionVector.at(a).SequenceType ==
Finish)
15457 if((a == z + 1) && (FoundStopTime == TLSTEntry.
ArrTime) && ((ActionVector.at(a).LinkedTrainEntryPtr > 0) || (ActionVector.at(a).NonRepeatingShuttleLinkEntryPtr > 0)))
15460 LocServiceTimesVector.pop_back();
15461 SkipAddingMinutes =
true;
15466 if(FoundStopTime ==
"")
15468 throw Exception(
"Failure to determine FoundStopTime for SequenceType == Start");
15470 if(!SkipAddingMinutes)
15472 int WhileCount = 0;
15481 if(IncTime >= FoundStopTime)
15485 LocServiceTimesVector.push_back(TLSTEntry);
15486 if(WhileCount > 2000)
15488 throw Exception(
"While loop failed to break in 2000 loops for SequenceType == Start");
15497 if((TLSTEntry.
Location == LocServiceTimesVector.back().Location) && (TLSTEntry.
ServiceAndRepeatNum == LocServiceTimesVector.back().ServiceAndRepeatNum))
15499 if(TLSTEntry.
DepTime == LocServiceTimesVector.back().ArrTime)
15501 TLSTEntry.
ArrTime = LocServiceTimesVector.back().ArrTime;
15502 LocServiceTimesVector.pop_back();
15503 LocServiceTimesVector.push_back(TLSTEntry);
15508 LocServiceTimesVector.push_back(TLSTEntry);
15514 LocServiceTimesVector.push_back(TLSTEntry);
15533 LocServiceTimesVector.push_back(TLSTEntry);
15537 AnsiString TempDepTime = TLSTEntry.
DepTime;
15539 LocServiceTimesVector.push_back(TLSTEntry);
15541 while(TLSTEntry.
AtLocTime < TempDepTime)
15546 TLSTEntry.
DepTime = TempDepTime;
15547 LocServiceTimesVector.push_back(TLSTEntry);
15551 LocServiceTimesVector.push_back(TLSTEntry);
15569 AnsiString HString;
15570 AnsiString VString;
15573 HString =
'N' + AnsiString(HLoc).SubString(2, AnsiString(HLoc).Length() - 1);
15577 HString = AnsiString(HLoc);
15581 VString =
'N' + AnsiString(VLoc).SubString(2, AnsiString(VLoc).Length() - 1);
15585 VString = AnsiString(VLoc);
15587 TLSTEntry.
Location = HString +
'-' + VString;
15589 LocServiceTimesVector.push_back(TLSTEntry);
15594 AnsiString FrhTime;
15595 if(ActionVector.at(z - 1).ArrivalTime != TDateTime(-1))
15599 else if(ActionVector.at(z - 1).EventTime != TDateTime(-1))
15607 LocServiceTimesVector.push_back(TLSTEntry);
15613 LocServiceTimesVector.push_back(TLSTEntry);
15618 else if(AVE.
Command ==
"Frh-sh")
15620 if(y == NumTrains - 1)
15626 LocServiceTimesVector.push_back(TLSTEntry);
15632 LocServiceTimesVector.push_back(TLSTEntry);
15651 TLocServiceTimesVector::iterator Ptr1, Ptr2;
15654 AnsiString TTFileName3 = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
15655 TTFileName3 = CurDir +
"\\Formatted timetables\\Conflict Analysis " + TTFileName3 +
"; " + RailwayTitle +
"; " + TimetableTitle +
".csv";
15657 std::ofstream TTFile3(TTFileName3.c_str());
15661 ShowMessage(
"Conflict Analysis file failed to open - can't be created");
15666 if(LocServiceTimesVector.empty())
15668 ShowMessage(
"No timetabled services found");
15670 DeleteFile(TTFileName3);
15675 TTFile3 <<
"Timetable analysis for timetable: '" + TimetableTitle +
"' in conjunction with railway: '" + RailwayTitle +
"'\n\n\n";
15682 Ptr1 = LocServiceTimesVector.begin();
15684 while(Ptr2 != LocServiceTimesVector.end())
15686 while(Ptr2->Location == Ptr1->Location)
15689 if(Ptr2 == LocServiceTimesVector.end())
15696 if(Ptr2 != LocServiceTimesVector.end())
15704 TTFile3 <<
"Arrival analysis: an asterisk means that the number of same approach code arrivals is equal to or greater than the number of platforms.\n";
15705 TTFile3 <<
"If the total number of arrivals exceeds the number of platforms the 'Trains present at location analysis' will show an asterisk.\n\n";
15706 MinuteString =
" minutes";
15707 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
15710 MinuteString =
" minute";
15712 TTFile3 <<
"Location,Number of,Number of,Services arriving within " << AnsiString(ArrRange) << MinuteString <<
" with their arrival times and approach codes\n";
15713 TTFile3 <<
",Platforms,Trains\n\n";
15715 Ptr1 = LocServiceTimesVector.begin();
15717 while(Ptr2 != LocServiceTimesVector.end())
15719 PreviousService =
"";
15720 NumTrainsAtLoc = 0;
15721 ServiceAndRepeatNumTotal =
"";
15723 NumPlatsAtThisLocCalculated =
false;
15725 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
15727 PreviousService =
"";
15728 NumTrainsAtLoc = 0;
15729 ServiceAndRepeatNumTotal =
"";
15731 NumPlatsAtThisLocCalculated =
false;
15735 if(Ptr2 == LocServiceTimesVector.end())
15740 if(Ptr2 == LocServiceTimesVector.end())
15744 while(Ptr2->Location == Ptr1->Location)
15746 PreviousService =
"";
15747 NumTrainsAtLoc = 0;
15748 ServiceAndRepeatNumTotal =
"";
15749 BasicTime = Ptr1->ArrTime;
15750 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
15754 while(!
WithinTimeRange(0, BasicTime, Ptr2->ArrTime, ArrRange) || ((Ptr1->ArrTime ==
"") && (Ptr2->ArrTime ==
"")))
15756 BasicTime = Ptr2->ArrTime;
15759 if(Ptr2 == LocServiceTimesVector.end())
15763 if(Ptr2->Location != Ptr1->Location)
15768 if(Ptr2 == LocServiceTimesVector.end())
15772 if(Ptr2->Location != Ptr1->Location)
15778 if((Ptr1->ArrTime ==
"") && (Ptr2->ArrTime ==
""))
15782 if(!NumPlatsAtThisLocCalculated)
15785 NumPlatsAtThisLocCalculated =
true;
15787 if(Ptr1->ServiceAndRepeatNum != PreviousService)
15789 if(ServiceAndRepeatNumTotal ==
"")
15791 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum +
"," + Ptr1->ArrTime;
15792 NumTrainsAtLoc = 1;
15796 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum +
"," + Ptr1->ArrTime;
15799 PreviousService = Ptr2->ServiceAndRepeatNum;
15800 if(ServiceAndRepeatNumTotal ==
"")
15802 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum +
"," + Ptr2->ArrTime;
15803 NumTrainsAtLoc = 1;
15807 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum +
"," + Ptr2->ArrTime;
15811 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (!
WithinTimeRange(2, BasicTime, Ptr2->ArrTime, ArrRange)))
15813 int MaxNumberOfSameDirections = 0;
15814 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTArrDep(1, ServiceAndRepeatNumTotal, NumTrainsAtLoc, Ptr1->Location,
true, AnalysisError, MaxNumberOfSameDirections);
15819 throw Exception(ServiceAndRepeatNumTotalOutput.c_str());
15823 AnsiString Asterisk =
"";
15824 if(MaxNumberOfSameDirections >= NumPlats)
15829 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
15830 ArrivalsPrinted =
true;
15831 ServiceAndRepeatNumTotal =
"";
15833 if(Ptr2 == LocServiceTimesVector.end())
15837 if(Ptr2->Location != Ptr1->Location)
15842 if(Ptr2 == LocServiceTimesVector.end())
15848 if(!ArrivalsPrinted)
15850 TTFile3 <<
"Nothing to report for arrivals";
15852 TTFile3 <<
"\n\n\n";
15860 Ptr1 = LocServiceTimesVector.begin();
15862 while(Ptr2 != LocServiceTimesVector.end())
15864 while(Ptr2->Location == Ptr1->Location)
15867 if(Ptr2 == LocServiceTimesVector.end())
15874 if(Ptr2 != LocServiceTimesVector.end())
15881 TTFile3 <<
"Departure analysis: an asterisk means that the number of same exit code departures is equal to or greater than the number of platforms.\n";
15882 TTFile3 <<
"If the total number of departures exceeds the number of platforms the 'Trains present at location analysis' will show an asterisk.\n\n";
15883 MinuteString =
" minutes";
15884 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
15887 MinuteString =
" minute";
15889 TTFile3 <<
"Location,Number of,Number of,Services departing within " << AnsiString(DepRange) << MinuteString <<
" with their departure times and exit codes\n";
15890 TTFile3 <<
",Platforms,Trains\n\n";
15892 Ptr1 = LocServiceTimesVector.begin();
15894 while(Ptr2 != LocServiceTimesVector.end())
15896 PreviousService =
"";
15897 NumTrainsAtLoc = 0;
15898 ServiceAndRepeatNumTotal =
"";
15900 NumPlatsAtThisLocCalculated =
false;
15902 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
15904 PreviousService =
"";
15905 NumTrainsAtLoc = 0;
15906 ServiceAndRepeatNumTotal =
"";
15908 NumPlatsAtThisLocCalculated =
false;
15912 if(Ptr2 == LocServiceTimesVector.end())
15917 if(Ptr2 == LocServiceTimesVector.end())
15921 while(Ptr2->Location == Ptr1->Location)
15923 PreviousService =
"";
15924 NumTrainsAtLoc = 0;
15925 ServiceAndRepeatNumTotal =
"";
15926 BasicTime = Ptr1->DepTime;
15927 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
15931 while(!
WithinTimeRange(3, BasicTime, Ptr2->DepTime, DepRange) || ((Ptr1->DepTime ==
"") && (Ptr2->DepTime ==
"")))
15933 BasicTime = Ptr2->DepTime;
15936 if(Ptr2 == LocServiceTimesVector.end())
15940 if(Ptr2->Location != Ptr1->Location)
15945 if(Ptr2 == LocServiceTimesVector.end())
15949 if(Ptr2->Location != Ptr1->Location)
15955 if((Ptr1->DepTime ==
"") && (Ptr2->DepTime ==
""))
15959 if(!NumPlatsAtThisLocCalculated)
15962 NumPlatsAtThisLocCalculated =
true;
15964 if(Ptr1->ServiceAndRepeatNum != PreviousService)
15966 if(ServiceAndRepeatNumTotal ==
"")
15968 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum +
"," + Ptr1->DepTime;
15969 NumTrainsAtLoc = 1;
15973 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum +
"," + Ptr1->DepTime;
15976 PreviousService = Ptr2->ServiceAndRepeatNum;
15977 if(ServiceAndRepeatNumTotal ==
"")
15979 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum +
"," + Ptr2->DepTime;
15980 NumTrainsAtLoc = 1;
15984 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum +
"," + Ptr2->DepTime;
15988 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (!
WithinTimeRange(5, BasicTime, Ptr2->DepTime, DepRange)))
15990 int MaxNumberOfSameDirections = 0;
15991 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTArrDep(3, ServiceAndRepeatNumTotal, NumTrainsAtLoc, Ptr1->Location,
false, AnalysisError, MaxNumberOfSameDirections);
15996 throw Exception(ServiceAndRepeatNumTotalOutput.c_str());
16000 AnsiString Asterisk =
"";
16001 if(MaxNumberOfSameDirections >= NumPlats)
16006 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
16007 DeparturesPrinted =
true;
16008 ServiceAndRepeatNumTotal =
"";
16010 if(Ptr2 == LocServiceTimesVector.end())
16014 if(Ptr2->Location != Ptr1->Location)
16019 if(Ptr2 == LocServiceTimesVector.end())
16025 if(!DeparturesPrinted)
16027 TTFile3 <<
"Nothing to report for departures";
16029 TTFile3 <<
"\n\n\n";
16039 Ptr1 = LocServiceTimesVector.begin();
16041 while(Ptr2 != LocServiceTimesVector.end())
16043 while(Ptr2->Location == Ptr1->Location)
16046 if(Ptr2 == LocServiceTimesVector.end())
16053 if(Ptr2 != LocServiceTimesVector.end())
16060 TTFile3 <<
"Trains present at location analysis: an asterisk means that the number of trains at the location is greater than the number of platforms.\n\n";
16061 TTFile3 <<
"Location,Number of,Number of,Time,Services at the location at that time\n";
16062 TTFile3 <<
",Platforms,Trains,\n\n";
16063 AnsiString ServiceAndRepeatNumTotal =
"", ServiceAndRepeatNumTotalOutput =
"";
16064 Ptr1 = LocServiceTimesVector.begin();
16066 while(Ptr2 != LocServiceTimesVector.end())
16068 PreviousService =
"";
16069 ServiceAndRepeatNumTotal =
"";
16070 NumTrainsAtLoc = 0;
16072 NumPlatsAtThisLocCalculated =
false;
16074 while((Ptr2->Location != Ptr1->Location) || ((Ptr1->Location ==
"") && (Ptr2->Location ==
"")))
16076 PreviousService =
"";
16077 ServiceAndRepeatNumTotal =
"";
16078 NumTrainsAtLoc = 0;
16080 NumPlatsAtThisLocCalculated =
false;
16084 if(Ptr2 == LocServiceTimesVector.end())
16089 if(Ptr2 == LocServiceTimesVector.end())
16093 while(Ptr2->Location == Ptr1->Location)
16095 if(Ptr1->FrhMarker ==
"Frh")
16098 Ptr1->FrhMarker =
"FrhCounted";
16100 PreviousService =
"";
16101 NumTrainsAtLoc = 0;
16102 ServiceAndRepeatNumTotal =
"";
16103 if((Ptr1->Location ==
"") && (Ptr2->Location ==
""))
16107 while((Ptr2->AtLocTime != Ptr1->AtLocTime) || ((Ptr1->AtLocTime ==
"") && (Ptr2->AtLocTime ==
"")))
16110 if(Ptr1->FrhMarker ==
"Frh")
16113 Ptr1->FrhMarker =
"FrhCounted";
16116 if(Ptr2 == LocServiceTimesVector.end())
16120 if(Ptr2->Location != Ptr1->Location)
16125 if(Ptr2 == LocServiceTimesVector.end())
16129 if(Ptr2->Location != Ptr1->Location)
16133 while(Ptr2->AtLocTime == Ptr1->AtLocTime)
16135 if((Ptr1->AtLocTime ==
"") && (Ptr2->AtLocTime ==
""))
16139 if(!NumPlatsAtThisLocCalculated)
16142 NumPlatsAtThisLocCalculated =
true;
16144 if(Ptr1->ServiceAndRepeatNum != PreviousService)
16146 if(ServiceAndRepeatNumTotal ==
"")
16148 ServiceAndRepeatNumTotal = Ptr1->ServiceAndRepeatNum;
16149 NumTrainsAtLoc = 1;
16153 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr1->ServiceAndRepeatNum;
16156 PreviousService = Ptr2->ServiceAndRepeatNum;
16157 if(ServiceAndRepeatNumTotal ==
"")
16159 ServiceAndRepeatNumTotal = Ptr2->ServiceAndRepeatNum;
16160 NumTrainsAtLoc = 1;
16164 ServiceAndRepeatNumTotal = ServiceAndRepeatNumTotal +
"," + Ptr2->ServiceAndRepeatNum;
16167 if(Ptr1->FrhMarker ==
"Frh")
16170 Ptr1->FrhMarker =
"FrhCounted";
16173 if((Ptr2 == LocServiceTimesVector.end()) || (Ptr2->Location != Ptr1->Location) || (Ptr2->AtLocTime != Ptr1->AtLocTime))
16177 ServiceAndRepeatNumTotalOutput =
ConsolidateSARNTAtLoc(1, ServiceAndRepeatNumTotal, NumTrainsAtLoc);
16179 if((NumTrainsAtLoc > 1) && ((FrhCount < NumTrainsAtLoc) || (FrhCount != LastFrhCount)))
16181 AnsiString Asterisk =
"";
16182 if(NumTrainsAtLoc > NumPlats)
16189 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
"," << ServiceAndRepeatNumTotalOutput <<
'\n';
16191 else if(FrhCount == 1)
16193 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
" (1 remains here)," << ServiceAndRepeatNumTotalOutput <<
'\n';
16197 TTFile3 << Asterisk << Ptr1->Location <<
"," << NumPlats <<
"," << NumTrainsAtLoc <<
"," << Ptr1->AtLocTime <<
" (" << FrhCount <<
" remain here)," << ServiceAndRepeatNumTotalOutput <<
'\n';
16199 LastFrhCount = FrhCount;
16200 PreviousServiceAndRepeatNumTotalOutput = ServiceAndRepeatNumTotalOutput;
16201 AtLocsPrinted =
true;
16202 ServiceAndRepeatNumTotal =
"";
16205 if(Ptr2 == LocServiceTimesVector.end())
16209 if(Ptr2->Location != Ptr1->Location)
16214 if(Ptr2 == LocServiceTimesVector.end())
16222 TTFile3 <<
"Nothing to report for trains at locations";
16224 TTFile3 <<
"\n\n\n";
16246 catch(
const Exception &e)
16248 AnsiString TTErrorFileName =
"Analysis Error.txt";
16249 TTErrorFileName = CurDir +
"\\Formatted timetables\\" + TTErrorFileName;
16250 std::ofstream TTError(TTErrorFileName.c_str());
16253 ShowMessage(
"Analysis error file failed to open - can't be created");
16257 AnsiString TimeNow = TDateTime::CurrentDateTime().FormatString(
"dd-mm-yyyy hh.nn.ss");
16258 TTError << TimeNow.c_str() <<
"\n" << ArrRange <<
"\n" << ArrChecked <<
"\n" << DepRange <<
"\n" <<
16259 DepChecked <<
"\n" << AtLocChecked <<
"\n" << AnsiString(e.Message);
16261 ShowMessage(
"Error in Conflict Analysis: A file called 'Analysis Error.txt' has been created in your Formatted timetables folder. Please send this file together with your railway and timetable files to railwayfeedback@gmail.com for investigation - many thanks");
16273 if((Time1 ==
"") || (Time2 ==
""))
16278 int Mins = Time1.SubString(4,2).ToInt();
16279 int Hours = Time1.SubString(1,2).ToInt();
16280 int Time1Mins = (Hours * 60) + Mins;
16281 Mins = Time2.SubString(4,2).ToInt();
16282 Hours = Time2.SubString(1,2).ToInt();
16283 int Time2Mins = (Hours * 60) + Mins;
16284 if(abs(Time1Mins - Time2Mins) <= MinuteRange)
16296 bool &AnalysisError,
int &MaxNumberOfSameDirections)
16302 AnsiString Output =
"", OneService =
"", TempStr1 =
"", TempStr2 =
"";
16304 std::list<AnsiString> ServiceList;
16306 bool EvenComma =
false;
16307 for(
int x = 1; x <= Input.Length(); x++)
16309 TempStr1 = Input[x];
16310 if(TempStr1 == AnsiString(
',') && EvenComma)
16316 TempStr2 += Input[x];
16318 if(TempStr1 == AnsiString(
','))
16320 EvenComma = !EvenComma;
16324 while(TempStr2.Length() > 0)
16326 SCPos = TempStr2.Pos(
';');
16329 OneService = TempStr2.SubString(1, SCPos - 1);
16330 ServiceList.push_back(OneService);
16331 TempStr2 = TempStr2.SubString(SCPos + 1, TempStr2.Length() - SCPos);
16335 ServiceList.push_back(TempStr2);
16339 ServiceList.sort();
16340 ServiceList.unique();
16341 NumTrainsAtLoc = ServiceList.size();
16344 int DirectionMarker = 0;
16346 std::list<AnsiString>::iterator SLIt, SLIt1, SLIt2, SLIt3;
16348 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
16350 *SLIt = *SLIt +
"&0";
16352 SLIt3 = ServiceList.end();
16354 AnsiString ServiceRef1, ServiceRef2, AnsiTime1, AnsiTime2, RepeatInfo1, RepeatInfo2;
16355 int AmpersandPos, SpacePos, CommaPos1, CommaPos2, RepeatNum1, RepeatNum2;
16356 TAllServiceCallingLocsMap::iterator ASCLIt1, ASCLIt2;
16358 MaxNumberOfSameDirections = 0;
16359 int SameDirectionCount = 0;
16361 for(std::list<AnsiString>::iterator SLIt1 = ServiceList.begin(); SLIt1 != SLIt3; SLIt1++)
16365 if(SLIt1->SubString(SLIt1->Length() - 1, 2) != AnsiString(
"&0"))
16371 CommaPos1 = SLIt1->Pos(
',');
16372 ServiceRef1 = SLIt1->SubString(1, CommaPos1 - 1);
16374 SpacePos = ServiceRef1.Pos(
' ');
16378 RepeatInfo1 = ServiceRef1.SubString(SpacePos + 2, ServiceRef1.Length() - SpacePos - 2);
16379 ServiceRef1 = ServiceRef1.SubString(1, SpacePos - 1);
16380 if(RepeatInfo1[1] ==
'F')
16386 SpacePos = RepeatInfo1.Pos(
' ');
16387 RepeatNum1 = RepeatInfo1.SubString(SpacePos + 1, RepeatInfo1.Length() - SpacePos).ToInt();
16390 AnsiTime1 = SLIt1->SubString(CommaPos1 + 1, SLIt1->Length() - CommaPos1);
16392 AmpersandPos = AnsiTime1.Pos(
'&');
16393 AnsiTime1 = AnsiTime1.SubString(1, AmpersandPos - 1);
16398 throw Exception(
"ASCLIt1 Error in " + Input);
16400 ServiceCallingLocsList1 = ASCLIt1->second;
16401 AmpersandPos = SLIt1->Pos(
'&');
16402 *SLIt1 = SLIt1->SubString(1, AmpersandPos);
16403 *SLIt1 = *SLIt1 + AnsiString(++DirectionMarker);
16405 SameDirectionCount = 1;
16406 for(SLIt2 = SLIt; SLIt2 != ServiceList.end(); SLIt2++)
16408 CommaPos2 = SLIt2->Pos(
',');
16409 ServiceRef2 = SLIt2->SubString(1, CommaPos2 - 1);
16411 SpacePos = ServiceRef2.Pos(
' ');
16415 RepeatInfo2 = ServiceRef2.SubString(SpacePos + 2, ServiceRef2.Length() - SpacePos - 2);
16416 ServiceRef2 = ServiceRef2.SubString(1, SpacePos - 1);
16417 if(RepeatInfo2[1] ==
'F')
16423 SpacePos = RepeatInfo2.Pos(
' ');
16424 RepeatNum2 = RepeatInfo2.SubString(SpacePos + 1, RepeatInfo2.Length() - SpacePos).ToInt();
16428 AnsiTime2 = SLIt2->SubString(CommaPos2 + 1, SLIt2->Length() - CommaPos2);
16430 AmpersandPos = AnsiTime2.Pos(
'&');
16431 AnsiTime2 = AnsiTime2.SubString(1, AmpersandPos - 1);
16436 throw Exception(
"ASCLIt2 Error in " + Input);
16438 ServiceCallingLocsList2 = ASCLIt2->second;
16440 if(
SameDirection(0, ServiceRef1, ServiceRef2, AnsiTime1, AnsiTime2, RepeatNum1, RepeatNum2, ServiceCallingLocsList1, ServiceCallingLocsList2, Location, Arrival))
16442 int AmpersandPos = SLIt2->Pos(
'&');
16443 *SLIt2 = SLIt2->SubString(1, AmpersandPos);
16444 *SLIt2 = *SLIt2 + AnsiString(DirectionMarker);
16445 SameDirectionCount++;
16448 if(SameDirectionCount > MaxNumberOfSameDirections)
16450 MaxNumberOfSameDirections = SameDirectionCount;
16455 if(SLIt3->SubString(SLIt3->Length() - 1, 2) == AnsiString(
"&0"))
16457 AmpersandPos = SLIt3->Pos(
'&');
16458 *SLIt3 = SLIt3->SubString(1, AmpersandPos);
16459 *SLIt3 = *SLIt3 + AnsiString(++DirectionMarker);
16463 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
16466 AmpersandPos = SLIt->Pos(
'&');
16467 AnsiString DirectionMarkerString = SLIt->SubString(AmpersandPos + 1, SLIt->Length() - AmpersandPos);
16468 AnsiString ServiceWithoutMarker = SLIt->SubString(1, AmpersandPos - 1);
16469 DirectionMarker = DirectionMarkerString.ToInt();
16470 AnsiString DirectionSuffix =
"";
16472 if(DirectionMarker < 27)
16474 c = 64 + DirectionMarker;
16475 DirectionSuffix =
"," + AnsiString(c);
16477 else if(DirectionMarker < 53)
16479 c = 65 + DirectionMarker - 27;
16480 DirectionSuffix =
",A" + AnsiString(c);
16484 DirectionSuffix =
",?";
16486 *SLIt = ServiceWithoutMarker + DirectionSuffix;
16489 for(SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
16491 Output = Output + *SLIt +
",";
16493 if(Output.Length() > 0)
16495 Output = Output.SubString(1, Output.Length() - 1);
16501 catch(
const Exception &e)
16503 AnalysisError =
true;
16514 AnsiString InternalInput = Input, Output =
"", OneService =
"";
16516 std::list<AnsiString> ServiceList;
16518 while(InternalInput.Length() > 0)
16520 CommaPos = InternalInput.Pos(
',');
16523 OneService = InternalInput.SubString(1, CommaPos - 1);
16524 ServiceList.push_back(OneService);
16525 InternalInput = InternalInput.SubString(CommaPos + 1, InternalInput.Length() - CommaPos);
16529 ServiceList.push_back(InternalInput);
16530 InternalInput =
"";
16534 ServiceList.sort();
16535 ServiceList.unique();
16536 NumTrainsAtLoc = ServiceList.size();
16537 for(std::list<AnsiString>::iterator SLIt = ServiceList.begin(); SLIt != ServiceList.end(); SLIt++)
16539 Output = Output + *SLIt +
",";
16541 if(Output.Length() > 0)
16543 Output = Output.SubString(1, Output.Length() - 1);
16556 AnsiString(RepeatNum1) +
"," + AnsiString(RepeatNum2) +
"," + Location);
16558 std::list<AnsiString>::iterator LP1 = 0, LP2 = 0, ListPtr1 = 0, ListPtr2 = 0, LocPtr1 = 0, LocPtr2 = 0;
16563 bool LocFound =
false;
16564 AnsiString Ref1 = Ref1In, Ref2 = Ref2In;
16566 TDateTime FirstServiceTime;
16569 int Ref1Target = 0, Ref1Count = 0;
16570 int SlashPos = Ref1.Pos(
'/');
16573 Ref1Target = Ref1.SubString(SlashPos + 1, Ref1.Length() - SlashPos).ToInt();
16574 Ref1 = Ref1.SubString(1, SlashPos - 1);
16576 int Ref2Target = 0, Ref2Count = 0;
16577 SlashPos = Ref2.Pos(
'/');
16580 Ref2Target = Ref2.SubString(SlashPos + 1, Ref2.Length() - SlashPos).ToInt();
16581 Ref2 = Ref2.SubString(1, SlashPos - 1);
16584 for(ListPtr1 = List1.begin(); ListPtr1 != List1.end(); ListPtr1++)
16586 if((*ListPtr1) == Location)
16588 LocPtr1 = ListPtr1;
16591 if(ListPtr1->SubString(1, 3) ==
"%%%")
16593 AnsiString CDTTime = ListPtr1->SubString(4, 5);
16598 FirstServiceTime = TDateTime(-1);
16599 bool BreakFlag =
false;
16602 if(TDVIt->ServiceReference == Ref1)
16604 if(Ref1Target > Ref1Count)
16609 IncMinutes = TDVIt->ActionVector.back().RearStartOrRepeatMins;
16610 for(TActionVector::iterator AVIt = TDVIt->ActionVector.begin(); AVIt != TDVIt->ActionVector.end(); AVIt++)
16614 FirstServiceTime = AVIt->EventTime;
16620 FirstServiceTime = AVIt->ArrivalTime;
16626 FirstServiceTime = AVIt->DepartureTime;
16637 if(IncMinutes == -1)
16639 throw Exception(
"Failed to find service for ServiceRef1 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
16641 if(FirstServiceTime == TDateTime(-1))
16643 throw Exception(
"Failed to find first service time for ServiceRef1 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
16647 if(!Arrival && (Time1 == CDTTime))
16652 if(Arrival && (Time1 == CDTTime))
16656 if(Time1 > CDTTime)
16661 if(Time1 < CDTTime)
16675 for(ListPtr2 = List2.begin(); ListPtr2 != List2.end(); ListPtr2++)
16677 if((*ListPtr2) == Location)
16679 LocPtr2 = ListPtr2;
16682 if(ListPtr2->SubString(1, 3) ==
"%%%")
16684 AnsiString CDTTime = ListPtr2->SubString(4, 5);
16689 FirstServiceTime = TDateTime(-1);
16690 bool BreakFlag =
false;
16693 if(TDVIt->ServiceReference == Ref2)
16695 if(Ref2Target > Ref2Count)
16700 IncMinutes = TDVIt->ActionVector.back().RearStartOrRepeatMins;
16701 for(TActionVector::iterator AVIt = TDVIt->ActionVector.begin(); AVIt != TDVIt->ActionVector.end(); AVIt++)
16705 FirstServiceTime = AVIt->EventTime;
16711 FirstServiceTime = AVIt->ArrivalTime;
16717 FirstServiceTime = AVIt->DepartureTime;
16728 if(IncMinutes == -1)
16730 throw Exception(
"IncMinutes -1 for ServiceRef2 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
16732 if(FirstServiceTime == TDateTime(-1))
16734 throw Exception(
"First service time -1 for ServiceRef2 in SameDirection " + Ref1In +
" " + Ref2In +
" " + Time1 +
" " + Time2 +
" " + AnsiString(RepeatNum1) +
" " + AnsiString(RepeatNum2) +
" " + Location);
16738 if(!Arrival && (Time2 == CDTTime))
16743 if(Arrival && (Time2 == CDTTime))
16747 if(Time2 > CDTTime)
16752 if(Time2 < CDTTime)
16768 LP1 = List1.begin();
16770 for(ListPtr1 = LocPtr1; ListPtr1 != LP1; ListPtr1--)
16772 if(ListPtr1 == List1.begin())
16776 if(ListPtr1->SubString(1, 3) ==
"%%%")
16783 LP2 = List2.begin();
16785 for(ListPtr2 = LocPtr2; ListPtr2 != LP2; ListPtr2--)
16787 if(ListPtr2 == List2.begin())
16791 if(ListPtr2->SubString(1, 3) ==
"%%%")
16801 for(ListPtr1 = LP1; ListPtr1 != List1.end(); ListPtr1++)
16803 if(ListPtr1 == LocPtr1)
16807 if(ListPtr1->SubString(1, 3) ==
"%%%")
16811 for(ListPtr2 = LP2; ListPtr2 != List2.end(); ListPtr2++)
16813 if(ListPtr2 == LocPtr2)
16817 if(ListPtr2->SubString(1, 3) ==
"%%%")
16821 if((*ListPtr1) == (*ListPtr2))
16834 LP1 = LocPtr1; LP1++;
16835 LP2 = LocPtr2; LP2++;
16836 for(ListPtr1 = LP1; ListPtr1 != List1.end(); ListPtr1++)
16838 if(ListPtr1 == List1.end())
16842 if(ListPtr1->SubString(1, 3) ==
"%%%")
16846 for(ListPtr2 = LP2; ListPtr2 != List2.end(); ListPtr2++)
16848 if(ListPtr2 == List2.end())
16852 if(ListPtr2->SubString(1, 3) ==
"%%%")
16856 if((*ListPtr1) == (*ListPtr2))
16873 if(ExitList.empty())
16879 if(StartName ==
"")
16881 if(ExitList.size() == 1)
16885 return " at " + ID;
16902 return " at " + StartName;
16941 AnsiString FormatStr =
"####0.0";
16942 AnsiString AvLateArrMins =
"";
16943 AnsiString AvEarlyArrMins =
"";
16944 AnsiString AvLatePassMins =
"";
16945 AnsiString AvEarlyPassMins =
"";
16946 AnsiString AvLateDepMins =
"";
16959 PerfFile <<
'\n' <<
'\n' <<
"***************************************";
16960 PerfFile <<
'\n' <<
'\n' <<
"Performance summary:" <<
'\n';
16968 PerfFile <<
LateArrivals <<
" late arrivals (average " << AvLateArrMins.c_str() <<
" min)" <<
'\n';
16970 PerfFile <<
LateArrivals <<
" late arrival (" << AvLateArrMins.c_str() <<
" min)" <<
'\n';
16975 PerfFile <<
EarlyArrivals <<
" early arrivals (average " << AvEarlyArrMins.c_str() <<
" min)" <<
'\n';
16977 PerfFile <<
EarlyArrivals <<
" early arrival (" << AvEarlyArrMins.c_str() <<
" min)" <<
'\n';
16982 PerfFile <<
OnTimePasses <<
" on-time passes" <<
'\n';
16987 PerfFile <<
LatePasses <<
" late passes (average " << AvLatePassMins.c_str() <<
" min)" <<
'\n';
16989 PerfFile <<
LatePasses <<
" late pass (" << AvLatePassMins.c_str() <<
" min)" <<
'\n';
16991 PerfFile <<
LatePasses <<
" late passes" <<
'\n';
16994 PerfFile <<
EarlyPasses <<
" early passes (average " << AvEarlyPassMins.c_str() <<
" min)" <<
'\n';
16996 PerfFile <<
EarlyPasses <<
" early pass (" << AvEarlyPassMins.c_str() <<
" min)" <<
'\n';
16998 PerfFile <<
EarlyPasses <<
" early passes" <<
'\n';
17001 PerfFile <<
OnTimeDeps <<
" on-time departures" <<
'\n';
17003 PerfFile <<
OnTimeDeps <<
" on-time departure" <<
'\n';
17006 PerfFile <<
LateDeps <<
" late departures (average " << AvLateDepMins.c_str() <<
" min)" <<
'\n';
17008 PerfFile <<
LateDeps <<
" late departure (" << AvLateDepMins.c_str() <<
" min)" <<
'\n';
17010 PerfFile <<
LateDeps <<
" late departures" <<
'\n';
17012 TDateTime TempExcessLCDownTime;
17023 if(TempExcessLCDownTime > TDateTime(0))
17029 AnsiString FormattedExcessLCDownMins = FormatFloat(FormatStr,
ExcessLCDownMins);
17032 PerfFile << FormattedExcessLCDownMins.c_str() <<
" excess minutes of level crossing barrier down time" <<
'\n';
17035 PerfFile <<
MissedStops <<
" missed stops" <<
'\n';
17037 PerfFile <<
MissedStops <<
" missed stop" <<
'\n';
17055 PerfFile <<
NumFailures <<
" train failures" <<
'\n';
17057 PerfFile <<
NumFailures <<
" train failure" <<
'\n';
17063 PerfFile <<
AvHoursIntValue <<
" hour mean time betweeen train failures" <<
'\n';
17067 PerfFile <<
AvHoursIntValue <<
" hours mean time betweeen train failures" <<
'\n';
17071 AnsiString AvLateMinsLocsNotReached =
"";
17077 if(LocsNotReached > 0)
17080 PerfFile << LocsNotReached <<
" locations that trains failed to reach (average lateness " << AvLateMinsLocsNotReached.c_str() <<
" min)" <<
'\n';
17084 PerfFile <<
SPADRisks <<
" SPAD risks" <<
'\n';
17086 PerfFile <<
SPADRisks <<
" SPAD risk" <<
'\n';
17094 PerfFile <<
Derailments <<
" derailments" <<
'\n';
17096 PerfFile <<
Derailments <<
" derailment" <<
'\n';
17103 PerfFile <<
'\n' <<
"***************************************" <<
'\n';
17105 bool DerailSPADFlag =
false, CrashFlag =
false;
17107 int OverallScorePercent = 100;
17109 double TotLateMinsFactor = 1;
17110 double MissedStopAndSPADRiskFactor = 1;
17111 double NetNegFactor = 1;
17120 OverallScorePercent = 5;
17121 DerailSPADFlag =
true;
17125 OverallScorePercent = 0;
17128 if(OverallScorePercent == 100)
17132 TotLateMinsFactor =
17140 NetNegFactor = TotLateMinsFactor * MissedStopAndSPADRiskFactor;
17142 OverallScorePercent = 100 * NetNegFactor;
17145 if((TotArrDep > 0) || DerailSPADFlag || CrashFlag)
17148 AnsiString OneFailureString =
", though the failure would account for some poor performance";
17149 AnsiString TwoOrMoreFailureString =
", though the failures would account for some poor performance";
17150 AnsiString AddedString =
"";
17152 AddedString = OneFailureString;
17154 AddedString = TwoOrMoreFailureString;
17155 PerfFile <<
"\nOverall score: " << OverallScorePercent <<
"%\n";
17156 AnsiString Rating =
"";
17157 if(OverallScorePercent == 100)
17158 Rating =
"Perfect!";
17159 else if(OverallScorePercent >= 95)
17160 Rating =
"Excellent";
17161 else if(OverallScorePercent >= 90)
17162 Rating =
"Very good";
17163 else if(OverallScorePercent >= 80)
17165 else if(OverallScorePercent >= 70)
17167 else if(OverallScorePercent >= 60)
17168 Rating =
"Unacceptable" + AddedString;
17169 else if(OverallScorePercent >= 50)
17170 Rating =
"Poor" + AddedString;
17171 else if(OverallScorePercent >= 40)
17172 Rating =
"Bad" + AddedString;
17173 else if(OverallScorePercent >= 30)
17174 Rating =
"Very bad" + AddedString;
17175 else if(OverallScorePercent >= 20)
17176 Rating =
"Terrible" + AddedString;
17177 else if(OverallScorePercent >= 10)
17178 Rating =
"Appalling" + AddedString;
17179 else if(OverallScorePercent >= 5)
17182 Rating =
"Disastrous - potential loss of life";
17185 Rating =
"Dire" + AddedString;
17187 else if(OverallScorePercent < 5)
17190 Rating =
"Catastrophic - loss of life";
17192 Rating =
"Abysmal";
17194 PerfFile <<
"Overall rating: " << Rating.c_str() <<
'\n';
17198 PerfFile <<
"\nThere were no timetabled departures or arrivals so there is insufficient information to provide a performance score or rating" <<
'\n';
17200 PerfFile <<
'\n' <<
"***************************************";
17209 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
17259 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
17291 int IncrementalMinutes = 0;
17303 bool TrainOperatingFlag =
false;
17308 TrainOperatingFlag =
true;
17312 if(TrainOperatingFlag)
17319 for(
unsigned int z = 0; z < TDEntry.
ActionVector.size(); z++)
17364 AnsiString HeadCode;
17368 for(
unsigned int x = 0; x <
TrainVector.size(); x++)
17372 HCandTrainPosParam.first = HeadCode;
17373 HCandTrainPosParam.second = TrainID;
17375 if((TimeToAct >= 0) && (TimeToAct < 59.9))
17378 OpTimeToActMultiMapEntry.first = TimeToAct;
17379 OpTimeToActMultiMapEntry.second = HCandTrainPosParam;
17409 float TimeToAct = 0;
17410 int DistanceToRedSignal = 0;
17413 ContinuationEntryVecPosVector.clear();
17414 bool LaterTrain =
false;
17418 LaterTrain =
false;
17419 if(CTEIt->second.TrainDataEntryPtr->TrainOperatingDataVector.at(CTEIt->second.RepeatNumber).RunningEntry !=
NotStarted)
17430 if(!ContinuationEntryVecPosVector.empty())
17432 for(
unsigned int x = 0; x < ContinuationEntryVecPosVector.size(); x++)
17434 if(CTEIt->second.VectorPosition == ContinuationEntryVecPosVector.at(x))
17436 LaterTrain =
true; ;
17447 ContinuationEntryVecPosVector.push_back(CTEIt->second.VectorPosition);
17448 AnsiString HeadCode = CTEIt->second.HeadCode;
17449 float CurrentStopTime;
17450 float LaterStopTime;
17451 float RecoverableTime;
17454 bool SigControlAndCanPassRedSignal =
false;
17458 SigControlAndCanPassRedSignal, &CTEIt->second.TrainDataEntryPtr->ActionVector.at(1),
17460 HeadCode, TrainID, CurrentStopTime, LaterStopTime, RecoverableTime, AvTrackSpeed);
17463 if(AvTrackSpeed < 30)
17465 if(DistanceToRedSignal == -1)
17471 int Speed = AvTrackSpeed;
17472 int MaxSpeed = int(CTEIt->second.TrainDataEntryPtr->MaxRunningSpeed);
17473 if(AvTrackSpeed > MaxSpeed)
17475 if(CTEIt->second.TrainDataEntryPtr->ActionVector.at(1).SignallerControl)
17478 Speed = CTEIt->second.TrainDataEntryPtr->SignallerSpeed;
17481 TimeToAct = LaterStopTime + DistanceToRedSignal * 3.6 / 60 / Speed;
17486 float MinsBefEnter = double(CTEIt->first -
TTClockTime) * 86400.0 / 60.0;
17487 TimeToAct += MinsBefEnter;
17490 HCandTrainPosParam.first = HeadCode;
17491 HCandTrainPosParam.second = -1 - CTEIt->second.VectorPosition;
17494 if(TimeToAct < 59.9)
17496 OpTimeToActMultiMapEntry.first = TimeToAct;
17497 OpTimeToActMultiMapEntry.second = HCandTrainPosParam;
17509 bool SigControlAndCanPassRedSignal,
TActionVectorEntry *AVPtr, AnsiString HeadCode,
int TrainID,
float &CurrentStopTime,
float &LaterStopTime,
17510 float &RecoverableTime,
int &AvTrackSpeed)
17519 AnsiString(TrackVectorPositionEntryPos) +
", " + AVPtr->
Command);
17520 int DistanceToRedSignal = 0;
17521 int CumTrackSpeed = 0;
17523 int TrackSpeedCount = 0;
17526 int CurrentElement = TrackVectorPosition;
17527 int CurrentEntryPos = TrackVectorPositionEntryPos;
17532 CurrentStopTime = 0;
17534 RecoverableTime = 0;
17535 if(CurrentElement == -1)
17540 int CurrentExitPos;
17545 if((CurrentEntryPos == 0) || (CurrentEntryPos == 2))
17548 CurrentExitPos = 1;
17550 CurrentExitPos = 3;
17553 CurrentExitPos = 0;
17586 CurrentStopTime = float(TimeToDepart);
17593 if((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0))
17604 else if(SigControlAndCanPassRedSignal)
17609 if((NextEntryPos == 0) || (NextEntryPos == 2))
17623 CurrentElement = NextElement;
17624 CurrentEntryPos = NextEntryPos;
17625 CurrentExitPos = NextExitPos;
17637 int LaterStopNumber = 0;
17641 while(!((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0)))
17650 if(CurrentEntryPos > 1)
17664 int TrainOnElement;
17671 if(CurrentEntryPos > 1)
17676 if((TrainOnElement > -1) && (TrainOnElement != TrainID))
17686 double StopTimeDouble;
17697 if(StopTimeDouble < 0.5)
17698 StopTimeDouble = 0.5;
17701 LaterStopTime += float(StopTimeDouble);
17702 RecoverableTime += StopTimeDouble - 0.5;
17703 if((LaterStopNumber == 1) && (TrainID > -1))
17709 if((AVPtr + 1)->FormatType ==
TimeLoc)
17713 StopTimeDouble = double((AVPtr + 1)->DepartureTime - AVPtr->
ArrivalTime) * 86400.0 / 60.0;
17715 if(StopTimeDouble < 0.5)
17716 StopTimeDouble = 0.5;
17718 LaterStopTime += float(StopTimeDouble);
17719 RecoverableTime += StopTimeDouble - 0.5;
17720 if((LaterStopNumber == 1) && (TrainID > -1))
17735 if(NextElement == -1)
17744 if((NextEntryPos == 0) || (NextEntryPos == 2))
17758 CurrentElement = NextElement;
17759 CurrentEntryPos = NextEntryPos;
17760 CurrentExitPos = NextExitPos;
17764 if((CurrentExitConfig ==
Signal) && (CurrentAttribute == 0))
17779 float MaxAllowableSpeed;
17781 if(TrackSpeedCount > 0)
17782 MaxAllowableSpeed = CumTrackSpeed / TrackSpeedCount;
17785 if(CurrentEntryPos > 1)
17795 float KmPerLocationStop;
17797 if(LaterStopNumber > 0)
17799 KmPerLocationStop = float(DistanceToRedSignal) / LaterStopNumber / 1000;
17800 AvTrackSpeed = (8.75 * KmPerLocationStop) + 44;
17804 AvTrackSpeed = (sqrt(
float(DistanceToRedSignal) / 1000) * 44) + 60;
17808 if(AvTrackSpeed > MaxAllowableSpeed)
17809 AvTrackSpeed = MaxAllowableSpeed;
17811 return DistanceToRedSignal;